-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Description
Laravel Version
12.48.1
PHP Version
8.3.30
Database Driver & Version
No response
Description
The Illuminate\Foundation\Console\DownCommand does not generate the correct except paths in a default Laravel 12.x app.
My bootstrap/app.php file is:
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
api: __DIR__.'/../routes/api.php',
commands: __DIR__.'/../routes/console.php',
channels: __DIR__.'/../routes/channels.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
$middleware->preventRequestsDuringMaintenance(except: [
'/api/*',
'/oauth/*',
'/webhooks/*',
]);
//...
})->create();However, the resulting storage/framework/down file is as follows as does not allow visiting those routes.
{
"except": [],
"redirect": null,
"retry": null,
"refresh": null,
"secret": null,
"status": 503,
"template": null
}
I believe this is because the DownCommand is resolving App\Http\Middleware\PreventRequestsDuringMaintenance out of the container, but that does not exist in a default Laravel 12.x app.
A temporary workaround is to add that file as follows:
<?php
namespace App\Http\Middleware;
class PreventRequestsDuringMaintenance extends \Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance {
}That correctly generates the following storage/framework/down file (also tested this issue affects cache and database drivers).
{
"except": [
"\/up",
"\/api\/*",
"\/oauth\/*",
"\/webhooks\/*"
],
"redirect": null,
"retry": null,
"refresh": null,
"secret": null,
"status": 503,
"template": null
}
Would the preferred fix for this bug be to
- Update the docs to highlight adding
App\Http\Middleware\PreventRequestsDuringMaintenanceis required? - Add that file in the default Laravel 12.x skeleton?
- Update
Illuminate\Foundation\Console\DownCommandto resolveIlluminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenanceinstead?
Thanks!
Steps To Reproduce
Add the following to bootstrap/app.php
$middleware->preventRequestsDuringMaintenance(except: [
'/api/*',
'/oauth/*',
'/webhooks/*',
]);Run php artisan down
The paths are not included in the except config.