Laravel 角色和路由认证
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16672064/
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 Roles and authentication to routes
提问by David Kirubi
I am looking to archive the the following
我希望存档以下内容
Userlogs in -> Assigned a privilege from the DB -> They can only see allowed routes only
用户登录 -> 从数据库分配权限 -> 他们只能看到允许的路由
So far i have been able to reach here:
到目前为止,我已经能够到达这里:
$user = Usercredential::where('username','=',Auth::user()->username)->get();
foreach ($user as $u ) {
$status = $u->userstatus;
$userPriv = $u->userpriviledge;
if ($status == 0){
Session::put('user_priv',$userPriv);
}
else{
return Redirect::to_route('home')->with('message','Inactive users cannot login');
}
Which checks the status of the user if active or inactive then stores the priviledge in my session. What next? How do i protect my routes?
它检查用户的状态是活动还是非活动,然后将权限存储在我的会话中。接下来是什么?我如何保护我的路线?
Thanks
谢谢
采纳答案by David Kirubi
For those in the future who are looking for this solution
对于未来正在寻找此解决方案的人
Will be very helpful, thanks Rodri for your pointer. I appreciate.
将非常有帮助,感谢罗德里的指点。我很欣赏。