Sunday, March 19, 2017

how to set middleware in laravel based on user role?

I am facing a problem with setting middleware in construct().

Every time i the later one is only selected, here the auth as middleware.

due to this my admin is kicked out to login page of user.

and without middleware i am facing problem with lfm as admin is asked to login in the laravel-filemanager window (user is allowed to browse).

Below is my code : public function __construct() {

    $middleware = '';
    if(Session::get('user_role') == 'admin'){
           $middleware = 'auth:admin';
        } else {
           $middleware =  'auth';
        }
    $this->middleware($middleware);
}



via PRINCE

Advertisement