Skip to content

Allow custom middlewares into EnsureFrontendRequestsAreStateful#561

Closed
coppolafab wants to merge 1 commit intolaravel:4.xfrom
coppolafab:ensure_frontend_requests_with_custom_middlewares
Closed

Allow custom middlewares into EnsureFrontendRequestsAreStateful#561
coppolafab wants to merge 1 commit intolaravel:4.xfrom
coppolafab:ensure_frontend_requests_with_custom_middlewares

Conversation

@coppolafab
Copy link

@coppolafab coppolafab commented Mar 9, 2025

This PR enables the use of customized middlewares with EnsureFrontendRequestsAreStateful.

In a Laravel project where Illuminate\Session\Middleware\StartSession is replaced with a custom middleware, EnsureFrontendRequestsAreStateful was still using the default middleware.

This change will benefit developers who want to replace the default middlewares with their custom implementations.

Problem Description
In a Laravel + Sanctum project configured as follows:

<?php
return Application::configure(basePath: dirname(__DIR__))
    ->withMiddleware(static function (Middleware $middleware): void {
        $middleware->web(
            replace: [
                StartSession::class => CustomStartSession::class,
            ],
        );

        $middleware->statefulApi();
        // ...
});

The routes under api group does not use the custom StartSession, and EnsureFrontendRequestsAreStateful uses the default hardcoded middleware. This forces developers to copy and paste the frontendMiddleware method, risking it becoming out of sync with future updates to Sanctum.

Additionally, all other middleware used by EnsureFrontendRequestsAreStateful are already configurable.

@taylorotwell
Copy link
Member

I am closing this pull request because it lacks sufficient explanation, tests, or both. It is difficult for us to merge pull requests without these things because the change may introduce breaking changes to the framework.

Feel free to re-submit your change with a thorough explanation of the feature and tests - integration tests are preferred over unit tests. Please include it's benefit to end users; the reasons it does not break any existing features; how it makes building web applications easier, etc.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants