路线 [companies.show] 未定义
Route [companies.show] not defined
我收到此错误消息(路线 [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');
在此先感谢您对我的帮助
将companies.show改为
return redirect()->route('company.show', ['company'=> $company->id])
->with('success' , 'Company updated successfully');
}
companies.show
未定义,因为您没有给路线命名。
Route::get('/companies/{id}', 'CompaniesController@showCompanyForID')->name('companies.show');
在您的 CompaniesController
和 return 中创建一个名为 showCompanyForID
的函数,并在您的请求中创建具有请求 ID 的公司。
use Illuminate\Http\Request;
public function showCompanyForID(Request $request)
{
$id = isset($request->id) ? $request->id : 0;
if ($id) {
// do work here
}
return view('companies.company')->with(compact('var1', 'var2'));
}
您现在可以重定向到该路线:
return redirect()
->route('companies.show')
->with(['company'=> $company->id, 'success' => 'Company updated successfully']);
要查看所有路线,cd
在 cmd / 终端中进入您的项目并输入:php artisan route:list
我收到此错误消息(路线 [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');
在此先感谢您对我的帮助
将companies.show改为
return redirect()->route('company.show', ['company'=> $company->id])
->with('success' , 'Company updated successfully');
}
companies.show
未定义,因为您没有给路线命名。
Route::get('/companies/{id}', 'CompaniesController@showCompanyForID')->name('companies.show');
在您的 CompaniesController
和 return 中创建一个名为 showCompanyForID
的函数,并在您的请求中创建具有请求 ID 的公司。
use Illuminate\Http\Request;
public function showCompanyForID(Request $request)
{
$id = isset($request->id) ? $request->id : 0;
if ($id) {
// do work here
}
return view('companies.company')->with(compact('var1', 'var2'));
}
您现在可以重定向到该路线:
return redirect()
->route('companies.show')
->with(['company'=> $company->id, 'success' => 'Company updated successfully']);
要查看所有路线,cd
在 cmd / 终端中进入您的项目并输入:php artisan route:list