首页 > 解决方案 > 路线 [companies.show] 未定义

问题描述

我收到此错误(Route [companies.show] 未定义。)我不知道该怎么做。实际上我正在更新 CompaniesController 中的数据并且数据正在更新但路由不起作用这是代码:

public function update(Request $request, Company $company){
$companyUpdate = Company::where('id', $company->id)->update(['name'=> $request->input('name'),'description'=> $request->input('description')]);
if($companyUpdate){
return redirect()->route('companies.show', ['company'=> $company->id])
      ->with('success' , 'Company updated successfully');
    }
 return back()->withInput();

我的 web.php 文件如下`

Route::get('/', function () {
return view('welcome');});
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Route::resource('/company','CompaniesController');

提前感谢您帮助我

标签: phplaravellaravel-5routeslaravel-5.5

解决方案


将公司更改为

return redirect()->route('company.show', ['company'=> $company->id])
  ->with('success' , 'Company updated successfully');
}

推荐阅读