0

I'm using laravel 5.2 with entrust/zizaco. When the user authenticates, they have the role admin, but when I put dd(1) in my app_user role middleware the request enters it !! The request also enters admin, and business_owner role middlewares. And even when the user logs out, after that each of their requests goes through auth middleware !!

Route::group(['middleware' => 'auth'], function () {
    Route::group(['middleware' => ['role:admin']], function (){
       // Routes go here
    });

    Route::group(['middleware' => ['role:app_user']], function (){
        // Routes go here
    });

    Route::group(['middleware' => ['role:business_owner']], function (){
       // Routes go here
    });
});
Hamidreza Bayat
  • 103
  • 1
  • 10

1 Answers1

0

Yes, request should enter in authenticate middleware and you can write your codes in middleware. This is laravel built in middleware for authenticate users:

public function handle($request, Closure $next)
    {
        if ($this->auth->guest()) { // if user isn't authenticated
            if ($request->ajax()) { // if request is ajax
                return response('Unauthorized.', 401); // return 401 res
            } else {
                return redirect()->guest('login'); // else redirect login page
            }
        }
        return $next($request); // return next res(e.g dashboard) if user is authenticated
    }