简体   繁体   English

适用于经过身份验证的用户的Laravel路由保护

[英]Laravel Route protection for authenticated users

I have couple of links similar to the below that I would like to protect by a condition that only logged-in users can access the specified views. 我有几个类似于下面的链接,我希望通过这样的条件来保护它们:只有登录的用户才能访问指定的视图。

Here the route sample I would like to protect: 这是我要保护的路线样本:

Route::get('home', array('as' => 'home', 'uses' => 'MembersController@loadHome'));

I would like to check if users are authenticated array 我想检查用户是否通过了身份验证

'before' => 'auth'

How can I modify the above route to include the before => auth ? 如何修改上述路由以包含before => auth?

Thanks in advance. 提前致谢。

Route::get('home', array('before' => 'auth', 'as' => 'home', 'uses' => 'MembersController@loadHome'));

Like that or you can protect a group of routes like so; 这样,或者您可以像这样保护一组路线;

Route::group(array('before' => 'auth'), function(){

     Route::get('home', array('as' => 'home', 'uses' => 'MembersController@loadHome'));
     Route::get('another', array('as' => 'another', 'uses' => 'Controller@method'));
     .....

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM