Skip to content

Instantly share code, notes, and snippets.

@ercanertan
Last active December 19, 2018 17:57
Show Gist options
  • Save ercanertan/f7f173271c0d2a8cfd49c033e126daa0 to your computer and use it in GitHub Desktop.
Save ercanertan/f7f173271c0d2a8cfd49c033e126daa0 to your computer and use it in GitHub Desktop.
Laravel redirectTo() method
// Dont use "return redirect.." because the method redirectTo should return an url path, not the Redirect response.
Example
protected function redirectTo() {
if (Auth::check() && Auth::user()->role == 'visitor') {
// Dont use redirect
// return redirect('/visitor'); // Wrong
return route('backend.visitor');
}
elseif (Auth::check() && Auth::user()->role == 'editor') {
// Dont use redirect
// return redirect('/editor'); // Wrong
return route('backend.editor');
}
else {
// Dont use redirect
// return redirect('/admin'); // Wrong
return route('backend.dashboard');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment