我收到上面提到的错误,这里是我的方法代码
function customHeader($id, $user_id, Request $request){
if ($user_id == Auth::user()->id || Auth::user()->is_admin){
$method = $request->method();
// To show View
if($request->isMethod('GET')){
} // Create
elseif($request->isMethod('POST')){
// Delete
} elseif($request->isMethod('Delete')){
//Delete single
} else{
return redirect()->back();
}
}
上面的函数参数id仅在用户需要删除记录时才需要..我认为错误是由于id而我需要id变量。如果我删除那个$ id它适用于创建如何修复该错误
路线为
Route::any('/setting/custom-header/{id?}', 'SettingController@customHeader');
答案 0 :(得分:2)
function customHeader(Request $request, $id, $user_id = null){
if ($user_id == Auth::user()->id || Auth::user()->is_admin){
$method = $request->method();
// To show View
if($request->isMethod('GET')){
} // Create
elseif($request->isMethod('POST')){
// Delete
} elseif($request->isMethod('Delete')){
//Delete single
} else{
return redirect()->back();
}
}
更改参数顺序make request as first param,并赋予参数默认值。