Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

motinska94's avatar

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?

0 likes
3 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

You cannot have two routes on the same url

1 like
motinska94's avatar

@Sinnbeck wow, didn't know that, thanks! I guess I'll check the user role in the login method and redirect accordingly then.

jlrdw's avatar

A user is a user, use authentication for login, use authorization to determine what the logged in user can or cannot do.

I have never had to modify or create any kind of middleware, only use auth middleware.

Suggestions only.

1 like

Please or to participate in this conversation.