Laravel 路由的隐式绑定,路由资源隐式绑定问题.apiResource或resource参数的获取,形参名字

1. api.php路由
Route::apiResource('companyinfo','UserCompanyinfoController');

public function show(CompanyInfonew $companyinfo)
{
return $this->success($companyinfo);
}

如上例子,在使用apiResource或resource时,默认 show update delete的uri为
Route::get('api/companyinfo/{companyinfo}','UserCompanyinfoController@show');
Route::put('api/companyinfo/{companyinfo}','UserCompanyinfoController@update');  或parch
Route::delete('api/companyinfo/{companyinfo}','UserCompanyinfoController@destroy');

所以在控制器中进行隐式绑定时,形参必须是$companyinfo

2. 具体路由可以查看 php artisan route:list
如果有路由指向不存在的控制器会报错

参考 https://learnku.com/articles/6776/implicit-binding-and-display-binding-of-laravel-routing




原文地址:https://www.cnblogs.com/jackduan/p/13843166.html