[英]How to define a named routes in Laravel 5.1?
I am doing a simple authentication using AuthController in my page. 我在页面中使用AuthController进行简单的身份验证。 And in my route list I created a named route to login page just like this: 在我的路由列表中,我创建了一个登录页面的命名路由,如下所示:
//authentication routes
Route::get('auth/login', [
'as' => 'login', 'uses' => 'Auth\AuthController@getLogin'
]);
But when I tried to access in my url using this: 但是当我尝试使用以下方法访问我的网址时:
http://localhost:8000/login
I got an error: 我收到一个错误:
NotFoundHttpException in RouteCollection.php line 143:
in RouteCollection.php line 143
at RouteCollection->match(object(Request)) in Router.php line 746
at Router->findRoute(object(Request)) in Router.php line 655
at Router->dispatchToRoute(object(Request)) in Router.php line 631
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
...
Can you help me with this? 你能帮帮我吗?
It should be: 它应该是:
Route::get('login', [
'as' => 'login', 'uses' => 'Auth\AuthController@getLogin'
]);
The name "login" "as" parameter is only for referring to the route when you need a URL generated or something like that. 名称“login”“as”参数仅用于在您需要生成URL或类似内容时引用路由。 Your code does not mean that you can got to the path /login. 您的代码并不意味着您可以进入路径/登录。 To do that, you need to set the route like so: 要做到这一点,你需要像这样设置路线:
Route::get('login', [
'as' => 'login', 'uses' => 'Auth\AuthController@getLogin'
]);
To visit the route as you set, you need to go to: http://localhost:8000/auth/login 要在设置时访问路由,您需要访问: http:// localhost:8000 / auth / login
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.