laravel redirect url after login code example
Example 1: how to redirect to another page after login in laravel
protected function authenticated(Request $request, $user) {
if ($user->role_id == 1) {
return redirect('/admin');
} else if ($user->role_id == 2) {
return redirect('/author');
} else {
return redirect('/blog');
}
}
Example 2: redirect to attempting url after login laravel
The intended method on the redirector will redirect the user to the URL they
were attempting to access before being intercepted by the authentication
middleware. A fallback URI may be given to this method in case the intended
destination is not available.
if (Auth::attempt($credentials)) {
return redirect()->intended('dashboard');
}