Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[11.x] Auto-register commands in routes/console.php #52867

Open
wants to merge 1 commit into
base: 11.x
Choose a base branch
from

Conversation

SamuelNitsche
Copy link
Contributor

@SamuelNitsche SamuelNitsche commented Sep 20, 2024

While working on route registration in a Laravel app, I noticed some inconvenience when using the using callback of the withRouting method.
In particular, the main issue was that commands defined in routes/console.php were not registered anymore. When checking the docs, I saw that there is a way to register commands using the withCommands method.

However, to achieve the same behaviour of the withRouting method you must pass the routes/console.php file as a parameter.
I think the DX could be improved by checking if the routes/console.php file exists and if so, registering all commands (including their schedule) automatically. This should be a good sensible default since the routes/console.php file is the default way to register commands in Laravel 11.

So before:

return Application::configure(basePath: dirname(__DIR__))
    ->withCommands([
        __DIR__ . 'routes/console.php',
    ]);

and after:

return Application::configure(basePath: dirname(__DIR__))
    ->withCommands();

I couldn't find any existing tests for the ApplicationBuilder so I decided to also not add any in this PR.

@SamuelNitsche SamuelNitsche changed the title Auto-register commands in routes/console.php [11.x] Auto-register commands in routes/console.php Sep 20, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant