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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 07:48:04  来源:igfitidea点击:

Laravel Roles and authentication to routes

phpauthenticationlaravellaravel-routing

提问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

对于未来正在寻找此解决方案的人

http://net.tutsplus.com/tutorials/php/build-web-apps-from-scratch-with-laravel-filters-validations-and-files/

http://net.tutsplus.com/tutorials/php/build-web-apps-from-scratch-with-laravel-filters-validations-and-files/

Will be very helpful, thanks Rodri for your pointer. I appreciate.

将非常有帮助,感谢罗德里的指点。我很欣赏。

回答by Rodri_gore

I recommend you the Laravel 4 Package called: ENTRUSTwho provide a way to add Role-based

我向您推荐 Laravel 4 包,名为:ENTRUST提供了一种添加基于角色的方法