mercredi 13 septembre 2017

Laravel Redirect If Authenticated middleware

I have three type of users for the application, Each one have its own dashboard. I need a check that adminor any other user cannot see another user dashboard.

There is a middleware RedirectIfAuthenticated :

public function handle($request, Closure $next, $guard = null){

    if (Auth::guard($guard)->check() && auth()->user()->type == 'admin'){
        return redirect('/admin');
    }

    if (Auth::guard($guard)->check() && auth()->user()->type == 'author'){
        return redirect('/author');
    }

    if (Auth::guard($guard)->check() && auth()->user()->type == 'client'){
        return redirect('/client');
    }
}

Its under guest middleware.

The above code seems good to me but when i tests it, The browser says Too many redirects.

What am i doing wrong, What will be the best way to handle it.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire