【发布时间】:2018-03-04 18:19:17
【问题描述】:
我对 laravel 中的可排序菜单有疑问。如果我加载我的页面,它会给我一个致命错误,上面写着“在 web.php 第 49 行中找不到类'输入'”。
这是第 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', 'HomeController@index')->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 中
标签: laravel jquery-ui jquery-ui-sortable