I don't seem to completely understand your question, but in my opinion there are some points of improvement in this code. To begin with, I noticed your 'standard' routes are actually the same as the name of their roles. And I personally hate to use a switch-case statement :) Instead you could do it like this:
public function handle($request, Closure $next) {
if (Auth::check()) {
$role = Auth::user()->roles()->first()->name;
return redirect('/'.$role.'/dashboard');
}
else {
return redirect('/home')
}
return $next($request);
}
Or maybe consider doing it like this to just point them back from where they came from:
public function handle($request, Closure $next) {
if (Auth::check()) {
return redirect()->back()
}
else {
return redirect('/home')
}
return $next($request);
}
If I am logged in and accidentally go back to "/" I see the login form. In that case, I shouldn't see the form but should get redirected just like when I first logged in.
Route::get('/', function () {
if ( auth()->check()) return redirect('/home'); // the route you want the user to be redirected to.
return view('auth.login');
});