php - how To manage middlewares using laravel? -


i have create 3 users('super-admin','branch-admin','user'). trying when ' super-admin' login not gone other 2 users dashboard users('branch-admin,user'). show page "too many redirect " , when give url of other user in browser redirect dashboard own dashboard. , same these other 2 users????

routes:

route::group(['middleware'  =>  [ 'auth', 'isnotadmin']], function(){         route::get('/profile','profilecontroller@getindex');     });      route::group(['middleware'  =>  [ 'auth', 'isbranchadmin']], function(){         route::get('/branch','branchcontroller@gettindex');     });      route::group(['middleware'  =>  [ 'auth', 'isadmin']], function(){     route::get('/super/admin', 'admincontroller@getindex');         }); 

view:

<div class="col-xs-12 col-sm-12 col-md-3 col-lg-3">     @if(auth::check() && auth::user()->type === 'user')         <ul class="nav nav-pills nav-stacked">             <li role="presentation" class="active">                 <a id="bootstrap-overrides" href="/home">                     home                 </a>             </li>             <li role="presentation">                 <a id="bootstrap-overrides" href="/contact">                     contact                 </a>             </li>             <li role="presentation">                 <a id="bootstrap-overrides" href="/about">                                     </a>             </li>             <li role="presentation">                 <a id="bootstrap-overrides" href="/blog">                     blog                 </a>             </li>             <li role="presentation">                 <a id="bootstrap-overrides" href="/faqs">                     faqs                 </a>             </li>         </ul>     @elseif(auth::check() && auth::user()->type === 'admin')         <ul class="nav nav-pills nav-stacked">             <li role="presentation" @if(request::path() === 'companies') class="active" @endif>                 <a href="/companies">                     companies                 </a>             </li>             <li role="presentation" @if(request::path() === 'branchies') class="active" @endif>                 <a href="/branchies">                     branchies                 </a>             </li>         </ul>     @elseif(auth::check() && auth::user()->type === 'branchadmin')         <ul class="nav nav-pills nav-stacked">             <li role="presentation" @if(request::path() === 'medicines') class="active" @endif>                 <a href="/medicines">                     medicines                 </a>             </li>             <li role="presentation" @if(request::path() === 'stock') class="active" @endif>                 <a href="/stock">                     stock_details                 </a>             </li>         </ul>     @endif </div> 

middlewares:

branchadmin:

class branchadmin {     public function handle($request, closure $next){         if(auth::user()->type === 'branchadmin'){             return redirect('/branch/'.auth::user()->branch->id);         }         return $next($request);     } } 

userisadmin:

class userisadmin {     public function handle($request, closure $next)     {         if(auth::user()->type === 'admin'){             return redirect('/super/admin');         }         return $next($request);     } } 

userisnotadmin:

class userisnotadmin {     public function handle($request, closure $next)     {         if(auth::user()->type === 'user'){             return redirect('/profile');         }         return $next($request);     } } 

your middleware logic not seem right. think should have many redirects because of that. take 1 middleware example.

class userisnotadmin {     public function handle($request, closure $next)     {         if(auth::user()->type === 'user'){             return redirect('/profile');         }         return $next($request);     } } 

what saying

if user of type 'user', redirect them '/profile' 

therefore, if user of type 'user' goes http://website/profile, keeps redirecting them profile on , on again.

what should middleware for: stop intruders :). e.g: in userisnotadmin middleware, this

if( !auth::user()->type === 'user' ){     redirect('/home'); } return $next($request); 

translates

if user not of type 'user', send them home. else, let them in.  

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -