Ejemplo n.º 1
0
 public function testCheck()
 {
     $this->assertTrue(AccessHandler::check('admin', 'editor'), 'Admin users should have access to editor modules');
     $this->assertTrue(AccessHandler::check('editor', 'user'), 'Admin should have access to users modules');
     $this->assertTrue(AccessHandler::check('admin', 'admin'), 'Admin users should have access to admin modules');
     $this->assertFalse(AccessHandler::check('user', 'admin'), 'Users should not have access to admin modules, routes, etc.');
 }
Ejemplo n.º 2
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @param string $role
  * @return mixed
  */
 public function handle($request, Closure $next, $role)
 {
     $user = auth()->user();
     if (!AccessHandler::check($user->role, $role)) {
         abort(404);
     }
     return $next($request);
 }