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

Ahmad-Ahmad's avatar

guest middleware for API only routes?

this is a route of breeze API only starter kit fresh installation: Route::post('/register', [RegisteredUserController::class, 'store']) ->middleware('guest') ->name('register');

all other routes are like this.

as you can see it has the 'guest' middleware, which is typically used to redirect an authenticated user to another route if he tried to access register routes in stateful context, but when using it in stateless context it just lets you login at any time, so what is it exactly used for?

0 likes
5 replies
jlrdw's avatar

To register, once registered, credentials are verified and token based back and forth communication is used.

If using Sanctum read all three uses it has.

Ahmad-Ahmad's avatar

@jlrdw Maybe there is a misunderstanding here, I'm asking about the exact role the 'guest' middleware play and why is it used?

and doesn't it make more sense for it to be used with other starter kits like breeze with blade? ... because it is not used there.

another little question... does Breeze API only starter kit have a built in implementation for login? the login I see here in AuthenticatedSessionController is session based and not token based:

    {
        $request->authenticate();

        $request->session()->regenerate();

        return redirect()->intended(route('dashboard', absolute: false));
    }
Ahmad-Ahmad's avatar

@martinbean ok, but why isn't it used in some other starter kits like breeze with blade, how the redirection there is done?

Please or to participate in this conversation.