Issue
I am redirecting users based on their roles, I changed my AuthenticatedUsers.php and added this to the authenticated function
protected function authenticated(Request $request, $user)
{
if (Auth::user()->priority == 'HI') {
return view ('dashboard');
}else{
return view ('home');
}
}
Now I got it working to redirect based on roles, however when I refresh the page FOR THE FIRST TIME it shows
CONFIRM FORM RESUBMISSION
Solution
You are not redirecting the user, you are only rendering a view.
use redirect to redirect the user:
protected function authenticated(Request $request, $user)
{
if (Auth::user()->priority == 'HI') {
return redirect('dashboard');
// with named routes
return redirect()->route('dashboard');
} else {
return redirect('home');
// with named routes
return redirect()->route('home');
}
}
From the docs:
Redirect responses are instances of the Illuminate\Http\RedirectResponse class, and contain the proper headers needed to redirect the user to another URL. There are several ways to generate a RedirectResponse instance. The simplest method is to use the global redirect helper:
Route::get('dashboard', function () {
return redirect('home/dashboard');
});
When you call the redirect helper with no parameters, an instance of Illuminate\Routing\Redirector is returned, allowing you to call any method on the Redirector instance. For example, to generate a RedirectResponse to a named route, you may use the route method:
return redirect()->route('login');
Answered By - Remul
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.