简体   繁体   中英

Laravel 5 - Redirecting a user to a specific page based on their role on authentication

I am using the Bican Roles package with Laravel 5 and i'm trying to figure out how to modify the AuthController class to redirect a user to their designated page based on their role. I read on an article somewhere that i would need to create the method authenticate to override the default function but i'm unsure how i would include all the methods of the bican class. For example on the github page of bicon it says to use

$user->level to get the users level but i get an error,

protected function authenticated($user)
    {
        dd($user->level);
    }

If I understand the problem:

  1. You can create the middleware to checking user's role on specific routes.

  2. On your method authenticated() , variable $users is not defined. Documentation of bican/roles package uses shorthand of Auth::user() to get data of current user. So you should use:

     Auth::user()->is('YOUR_ROLE_NAME'); # To check user role Auth::user()->can('YOUR.ACTION'); # To check user permission Auth::user()->level(); # To check user level Auth::user()->allowed('ACTION', $someModel); # To check user permission to object

I read on an article somewhere that i would need to create the method authenticate to override the default function

Until that default function is in app directory, it pass. But Laravel controllers are so flexible that you can do it in another ways ( look first point ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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