我有一個關於laravel中可排序菜單的問題。如果我加載我的網頁,它給了我一個致命的錯誤,說「Class'Input'沒有在web.php第49行」中找到。與laravel排序的jquery不起作用
這是第49行的內容:「$ itemID = Input :: get('itemID');」。下面你看到整個代碼塊
Route::get('/custom',function(){
$menu = DB::table('orders')->orderBy('order','ASC')->get();
$itemID = Input::get('itemID');
$itemIndex = Input::get('itemIndex');
foreach($menu as $value){
return DB::table('orders')->where('menu_id','=',$itemID)->update(array('order'=> $itemIndex));
}});
這是我的jquery:
$('document').ready(function(){
$(function(){
$("#menu").sortable({
stop: function(){
$.map($(this).find('li'), function(el) {
var itemID = el.id;
var itemIndex = $(el).index();
$.ajax({
url:'{{URL::to("custom")}}',
type:'GET',
dataType:'json',
data: {itemID:itemID, itemIndex: itemIndex},
})
});
}
});
});
console.log(itemID);
});
這是我的路線文件:
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function() {
return view('home');
});
Auth::routes();
Route::get('/home', '[email protected]')->name('home');
Route::get('/custom', function(){
return view('custom');
});
Route::get('/custom-menu', function(){
return view('custom');
});
// function to view menu which are in order
Route::get('/', function() {
$menu = DB::table('orders')->orderBy('order','ASC')->get();
return view('custom-menu',['menus'=>$menu]);
});
// To view Menu That are in database
Route::get('custom',function(){
$menu = DB::table('orders')->orderBy('order','ASC')->get();
return view('custom',['menus'=>$menu]);
});
// Function to order menus
Route::get('/custom',function(){
$menu = DB::table('orders')->orderBy('order','ASC')->get();
$itemID = Input::get('itemID');
$itemIndex = Input::get('itemIndex');
foreach($menu as $value){
return DB::table('orders')->where('menu_id','=',$itemID)->update(array('order'=> $itemIndex));
}
});
是否有人知道我可以解決這個錯誤?
嘗試使用輸入;在web.php – RamAnji