コード例 #1
0
 /**
  * A basic test example.
  *
  * @return void
  */
 public function testExample()
 {
     $this->assertTrue(\App\AccessHandler::check('admin', 'editor'), 'Admin users should have access to editor modules');
     $this->assertTrue(\App\AccessHandler::check('editor', 'user'), 'Editor should have access to users modules');
     $this->assertTrue(\App\AccessHandler::check('admin', 'admin'), 'Admin users should have access to admin modules');
     $this->assertFalse(\App\AccessHandler::check('user', 'admin'), 'Users should not have access to admin modules');
 }
コード例 #2
0
ファイル: Role.php プロジェクト: juansleonc/base_laravel
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next, $role)
 {
     $user = auth()->user();
     if (!AccessHandler::check($user->role, $role)) {
         abort(404);
     }
     return $next($request);
 }