Laravel Roles and authentication to routes

两盒软妹~` 提交于 2019-12-24 03:05:37

问题


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


回答1:


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




回答2:


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/

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



来源:https://stackoverflow.com/questions/16672064/laravel-roles-and-authentication-to-routes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!