lundi 26 octobre 2015

Redirect if authenticated logic in Laravel's built-in auth?

This question has been asked before, and I believe my code to be correct, but I am getting strange behaviour.

I need to redirect the user to different routes after login depending on some database values. I thought that in order to do this I simply had to place my logic in the handle method of app/Http/Middleware/RedirectIfAuthenticated.php. My method currently looks like so:

public function handle($request, Closure $next)
{

    if ($this->auth->check()) {
        if($this->auth->user()->sign_up_complete == 1){
            return redirect('/');
        } else {
            if($this->auth->user()->step_one_complete == 0){
                return redirect('/register/step-1');
            } elseif($this->auth->user()->step_two_complete == 0){
                return redirect('/register/step-2');
            } else {
                return redirect('/');
            }
        }
    }

    return $next($request);
}

This does not work, and upon login the user is redirected to /home. I have tried placing dd($this->auth->user()) inside the $this->auth->check() condition, but it never gets run. If I place it outside of that check then it's run on every request. It looks like $this->auth->check() is never run.

My question: If not here, where should this logic go?

I have removed protected $redirectTo = '/account'; from the AuthController.php controller too.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire