即使定义了路由,laravel 中的路由未定义错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41189695/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Route not defined error in laravel , even though route is defined
提问by Alexander Solonik
I have the followning method in my controller:
我的控制器中有以下方法:
public function showQualityResult($qualityData) {
return $qualityData;
}
When clicked on a link , i want that method to be invoked , so i have the following in my view file:
单击链接时,我希望调用该方法,因此我的视图文件中有以下内容:
<a href="{{ route('showQualityResult' , Session::get('quality-data')) }}">Submited Quality Check</a>
Also, I have the following route setup:
另外,我有以下路线设置:
Route::get('/showQualityResult', 'QualityCheckController@showQualityResult');
But having the below line of code:
但是有以下代码行:
<a href="{{ route('showQualityResult' , Session::get('quality-data')) }}">Submited Quality Check</a>
Does't really work , i get the following error in the frontEnd:
真的不起作用,我在前端收到以下错误:
Now how can i solve this problem , and why am i getting this error of Route not defined , even though i have the route defined ??
现在我该如何解决这个问题,为什么我会收到这个 Route not defined 错误,即使我已经定义了路由??
回答by Alexey Mezenin
route()
helper uses route name to build URL, so you need to use it like this:
route()
helper 使用路由名称来构建 URL,因此您需要像这样使用它:
route('quality-result.show', session('quality-data'));
And set a name for the route:
并为路由设置一个名称:
Route::get('/showQualityResult', ['as' => 'quality-result.show', 'uses' => 'QualityCheckController@showQualityResult']);
Or:
或者:
Route::get('/showQualityResult', 'QualityCheckController@showQualityResult')->name('quality-result.show');
The route function generates a URL for the given named route
route 函数为给定的命名路由生成一个 URL
https://laravel.com/docs/5.3/routing#named-routes
https://laravel.com/docs/5.3/routing#named-routes
If you don't want to use route names, use url()
instead of route()
回答by Devon
The route()
helper looks for a named route, not the path.
该route()
助手查找名为路线,而不是路径。
https://laravel.com/docs/5.3/routing#named-routes
https://laravel.com/docs/5.3/routing#named-routes
Route::get('/showQualityResult', 'QualityCheckController@showQualityResult')
->name('showQualityResult');
Should fix the issue for you.
应该为您解决问题。
回答by spedley
In my case I had simply made a stupid mistake.
就我而言,我只是犯了一个愚蠢的错误。
Further down in my code I had another named route (properly named with a unique name) but an identical path to the one Laravel told me it couldn't find.
在我的代码中,我有另一个命名的路由(用唯一的名称正确命名),但是与 Laravel 告诉我它找不到的路径相同。
A quick update to the path fixed it.
对路径的快速更新修复了它。