Skip to content

Down command not including except #58559

@davidrushton

Description

@davidrushton

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

  1. Update the docs to highlight adding App\Http\Middleware\PreventRequestsDuringMaintenance is required?
  2. Add that file in the default Laravel 12.x skeleton?
  3. Update Illuminate\Foundation\Console\DownCommand to resolve Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance instead?

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions