You cannot have two routes on the same url
Feb 19, 2023
3
Level 3
How to continue middleware without returning anything?
I have a UserRoleMiddleware like this :
public function handle(Request $request, Closure $next, $role)
{
$roles = ["employee", "employer", "support", "admin"];
if(Auth::check() && $roles[Auth::user()->role] == $role)
{
return $next($request);
}
return response()->view('welcome');
}
I also have routes like this :
Route::middleware(['auth', 'user-role:employee'])->as('employee.')->group(function(){
Route::get('/', [PanelController::class, 'index'])->name('index');
});
Route::middleware(['auth', 'user-role:employer'])->as('employer.')->group(function(){
Route::get('/', [BossPanelController::class, 'index'])->name('index');
});
But since php checks routes one by one in the order its written, if first route group returns the default welcome blade, it doesn't even go into second route and check if user role is employer.
Any idea how can I fix this?
Level 102
1 like
Please or to participate in this conversation.