Laravel 5.1 路线未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33321494/
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
Laravel 5.1 Route not defined
提问by xmarston
I'm developing a webapp with Laravel 5.1 and I started doing the user authentication, I added this routes to the routes.php file:
我正在使用 Laravel 5.1 开发一个 web 应用程序,并开始进行用户身份验证,我将此路由添加到了 routes.php 文件中:
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::get('auth/logout', 'Auth\AuthController@getLogout');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::post('auth/register', 'Auth\AuthController@postRegister');
And it works if I enter the link into the url bar but if I put in a template this syntax:
如果我将链接输入到 url 栏中,它会起作用,但是如果我在模板中输入此语法:
<a href="{{ URL::route('auth/register') }}">Registra't</a>
I get the error Route [auth/register] not defined. What I'm doing wrong? Is there anything else to do?
我收到错误 Route [auth/register] 未定义。我做错了什么?还有什么可做的吗?
回答by Akshendra Pratap
URL::route()
expect a named route, here you should use URL::to()
or you can create a named route with
URL::route()
期待一个命名路由,在这里你应该使用URL::to()
或者你可以创建一个命名路由
Route::get('auth/register', [
'as' => 'register',
'uses' => 'Auth\AuthController@getRegister'
]);
Then use URL::route('register')
to link to the route auth/register
然后使用URL::route('register')
链接到路由auth/register
回答by Michael Chekin
Because you haven't defined a Named route and URL::route
accepts route name as it's first parameter. You just defined a path auth/register
.
因为您还没有定义命名路由并URL::route
接受路由名称作为它的第一个参数。您刚刚定义了一个路径auth/register
。
To define Named Route you can do this:
要定义命名路由,您可以执行以下操作:
Route::post('auth/register', [
'as' => 'auth/register', 'uses' => 'Auth\AuthController@postRegister'
]);
回答by Le Trong Tuan
Just put
Auth::routes();
in routes/web.php
只要把
Auth::routes();
在routes/web.php
回答by Elliot Robert
This did the trick for me when using auth0 tutorial
php artisan cache:clear
php artisan view:clear
php artisan route:clear
php artisan config:clear
回答by Brayan LP
work for me, putting "as" and call the route for example:
对我来说有效,输入“as”并调用路线,例如:
Route::get('auth/logout', ['as' => 'auth/logout','uses'=>'Auth\AuthController@getLogout']);
and for the HTML: y para el HTML:
对于 HTML: y para el HTML:
<li><a href="{{route('auth/logout')}}">Logout</a></li>
this solution work for me in Laravel 5.1
这个解决方案在 Laravel 5.1 中对我有用