authentication - Protect routes with middleware Laravel -


i have implemented middleware roles , permissions control in app, cannot figure out why allows me define 1 '/' route. second 1 still pointing '/home' though override authcontroller redirectto variable.

my routes:

route::group(['middleware' => 'role:user'], function() {  route::get('/', 'scorescontroller@user');  });  route::group(['middleware' => 'role:admin'], function() { route::get('/', 'pagescontroller@home'); }); 

in case after authentication user user role redirecting '/home'.

like simon says second route override first 1 load controller wich redirects page via redirect() or write route itself.

could this:

route::get('/', function(){     $user = auth::user();      if($user->is('admin') {         return redirect('admin');     }else{         return redirect('user');     } });  route::get('admin', ['middleware' => 'role:admin', 'uses'=> 'pagescontroller@home']); 

this 1 of many possibilities hope helps you.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -