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

markotitel's avatar

Auth or Guest or both, middleware.

While watching Laravel from scratch 5.7, question arose about auth and guest middleware.

Can I authenticate multiple routes so I can apply Auth middleware just once in the codebase?

0 likes
5 replies
tykus's avatar
tykus
Best Answer
Level 104

Route groups:

Route::group(['middleware' => ['auth']], function () {
    // routes that require user to be authenticated
});

You might also see the middleware applied as a method (same result, different syntax):

Route::middleware(['auth'])->group(function () {
    // routes that require user to be authenticated
});
1 like
Cronix's avatar

I'd really suggest giving the docs a thorough reading through: https://laravel.com/docs/5.7/routing

You're only going to learn a certain % of the capabilities by watching the videos, which are a great supplement to the actual docs.

tykus's avatar

Exactly. You can define routes for both guest and non-authenticated users outside that group; or indeed have a route group for guests only (e.g. register, login):

Route::middleware(['guest'])->group(function () {
    // routes that require user to be authenticated
});

Please or to participate in this conversation.