How to use role management in laravel

Laravel

Posted on 31 Jan 15 by Vickey
  809



By using laravel packages we can manage user roles. but we can create a custom code to manage roles by using route file. For example if i am creating a function only access for admin then i can add a conditions in my routing

if(Auth::user()){

    if(Auth::user()->role_id==1){

        Route::get('/manageusers', 'AdminController@manageusers');
    }
    else {

           Route::get('/manageusers', function(){
           return Redirect::to('/');  });
    }
}

In this code user's role id is 1 then manageusers function can accessed otherwise it will redirect to home page


If this post help you reduce time to develop, you can help me to maintain this website :)
www.000webhost.com