路由文件:-
Route::get('/Observation/{type}/list/{status}', 'ObservationController@index')->name('list_observation');
当前网址: localhost:8088/hse/public/Observation/status/list/2
Controller :
protected $type ;
protected $status ;
public function __construct(Request $request)
{
$this->middleware('auth')->except('getBuildings');
$this->status = Route::current()->parameter('status');
$this->type = Route::current()->parameter('type');
}
public function index()
{
if ($this->status == 'all'){
$observations = Observation::all();
}
else {
$observations = Observation::where($this->Type(),$this->status)->get();
}
return view('observations._list')->with('observations',$observations);
}
public function Type(){
switch ($this->type){
case 'building':
$this->type = 'building_id';
break;
case 'status':
$this->type = 'status_id';
break;
}
return $this->type;
}
错误显示: [路线:list_observation] [URI:Observation/{type}/list/{status}] 缺少必需的参数。 ( View :
当我删除查询行中的 $this->Type() 方法时,错误消失。
$this->Type() 方法的返回值是: status_id
哪个是正确的数据库列名。
最佳答案
也许在 view
的某处或者您生成该 URL 的地方您没有将所有必需的参数传递给路由。
关于php - laravel 5.5 缺少 [Route : 所需的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47191141/