Skip to content

[13.x] Ensure bootstrap withMiddleware works for the DownCommand#58571

Merged
taylorotwell merged 7 commits intolaravel:masterfrom
jackbayliss:13.x-down-command-except
Feb 4, 2026
Merged

[13.x] Ensure bootstrap withMiddleware works for the DownCommand#58571
taylorotwell merged 7 commits intolaravel:masterfrom
jackbayliss:13.x-down-command-except

Conversation

@jackbayliss
Copy link
Contributor

@jackbayliss jackbayliss commented Jan 31, 2026

This was reported via #58559

Currently, to get excluded paths in app/bootstrap working with php artisan down, you need to create your own App\Http\Middleware\PreventRequestsDuringMaintenance middleware class.

This PR fixes it so the preventRequestsDuringMaintenance() configuration in bootstrap/app.php actually works with the down command. Which is recommended in statamic here

Before this fix, configuring it like this does nothing (with the file driver):

->withMiddleware(function (Middleware $middleware) {
    $middleware->preventRequestsDuringMaintenance(except: [
        '/api/*',
        '/oauth/*',
    ]);
    
    // When calling down..

    // Would give us just...: 
        "except": [
        "\/up"
    ],
    
    // This PR ensures we get... 
        "except": [
        "\/up",
        "\/api\/*"
        "\/oauth\/*"
    ],
})

I've also removed the App\Http\Middleware\PreventRequestsDuringMaintenance usage for the framework middleware, as afaik the middleware stuff went in Laravel 11 - not sure if you want to keep it, but can re-work this to check it exists first then fallback.

I've added the ConsoleKernel bit so console commands can access the middleware static proerties ie so DownCommand can access the excluded paths - but granted you may have a better way of doing it. But I believe it's safe as middleware classes only execute during HTTP requests? (I think) and this just makes sure the static stuff is available.

Targeted 13.x as is a B/C, and needs a good think.

I've included a test that fails without the changes. But couldn't figure out how to get a test to fully cover the need for the ConsoleKernel bit - however tested locally.

Any feedback welcome, maybe we just shouldn't cover this usage, dunno.

Cheers

@github-actions
Copy link

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@jackbayliss
Copy link
Contributor Author

jackbayliss commented Jan 31, 2026

This is failing cause 13.x needs catching up to 12x - Ive caught up to master, I've marked for review but will more than likely need some feedback.

Thanks!

@jackbayliss jackbayliss marked this pull request as ready for review January 31, 2026 15:00
@taylorotwell taylorotwell merged commit 0f3e74d into laravel:master Feb 4, 2026
44 checks passed
jackbayliss added a commit to jackbayliss/framework that referenced this pull request Feb 13, 2026
…avel#58571)

* Update ApplicationBuilder.php

* Update DownCommand.php

* Update MaintenanceModeTest.php

* Update DownCommand.php

* Simplify middleware instantiation in afterResolving

* try both

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
taylorotwell added a commit that referenced this pull request Feb 13, 2026
) (#58798)

* Update ApplicationBuilder.php

* Update DownCommand.php

* Update MaintenanceModeTest.php

* Update DownCommand.php

* Simplify middleware instantiation in afterResolving

* try both

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
jackbayliss added a commit to jackbayliss/framework that referenced this pull request Feb 16, 2026
…avel#58571)

* Update ApplicationBuilder.php

* Update DownCommand.php

* Update MaintenanceModeTest.php

* Update DownCommand.php

* Simplify middleware instantiation in afterResolving

* try both

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
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