What is the best way to configure route restriction in PHP Laravel 5? -


i'm new laravel 5 middleware - , added new user type == dev application. need set route restriction user type - in term of can/can't access.


so create

devmiddleware.php

<?php  namespace app\http\middleware;  use app\article; use closure, view ; use illuminate\contracts\auth\guard;  class devmiddleware {     /**      * guard implementation.      *      * @var guard      */     protected $auth;      /**      * create new filter instance.      *      * @param  guard  $auth      * @return void      */     public function __construct(guard $auth)     {         $this->auth = $auth;     }      /**      * handle incoming request.      *      * @param  \illuminate\http\request  $request      * @param  \closure  $next      * @return mixed      */     public function handle($request, closure $next)     {         if ($this->auth->getuser()->type !== "dev") {             return view::make('errors.404');         }          return $next($request);     } } 

i registered in

kernel.php

'dev' => 'app\http\middleware\devmiddleware',


i use in

routes.php

$router->group(['middleware' => ['auth', 'admin', 'dev' ] ], function() {      //any routes goes in here  }); 

when go route in there - keep getting 404 error.

i want able go routes.

what did wrong here ? how fix ?

you have 3 middlewares acting there, assuming dev 1 failing. paste content of other 2. also, using:

$this->auth->getuser()->type 

what do? if user admin may failing @ dev middleware (or other way around).

p.s: i'd recommend entrust package if need deal roles.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -