I examined many of these issues, they do not fit the real problem. I would like to redirect the user to a specific URL immediately after logging in, depending on the state of the user.
I know this can be archived by middleware, so I tried this in the \ Http \ Middleware \ RedirectIfAuthenticated.php application
class RedirectIfAuthenticated
{
public function handle($request, Closure $next, $guard = null)
{
if (Auth::User()->check()) {
$redirect = '/client';
if (Auth::user()->hasRole('admin')){
$redirect = '/admin';
}
return redirect($redirect);
}
return $next($request);
}
}
I understand that this will not work right after logging in. I would like to redirect the user depending on whether he is an administrator or a client. I know I can use: protected $ redirectPath = '/ url / to / redirect'; but I have some pages to redirect.
What is the best way to do this?
user5500750