Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Merged

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
@taylorotwell taylorotwell merged commit e216708 into laravel:11.x Sep 22, 2024
32 checks passed
@SamuelNitsche SamuelNitsche deleted the auto-register-console-routes branch September 22, 2024 16:49
@rodrigopedra
Copy link
Contributor

@taylorotwell when there are both commands in routes/console.php and app/Console/Commands this change only registers the commands in routes/console.php.

Luckily, I have a preparation Envoy script before deploying, as I never tested for a command availability.

@Cellard
Copy link

Cellard commented Sep 25, 2024

Schedules (php artisan schedule:list) are doubling now.

crynobone added a commit that referenced this pull request Sep 26, 2024
crynobone added a commit that referenced this pull request Sep 26, 2024
crynobone added a commit that referenced this pull request Sep 26, 2024
…e breaking change with the default `withRouting($console)` (#52939)

* Revert "Fix for not automatically registering commands in App\Console\Commands (#52903)"

This reverts commit d76b2f1.

* Revert "Auto-Register Commands in `routes/console.php` (#52867)"

This reverts commit e216708.
taylorotwell pushed a commit that referenced this pull request Sep 26, 2024
…e breaking change with the default `withRouting($console)` (#52942)

* Revert "Fix for not automatically registering commands in App\Console\Commands (#52903)"

This reverts commit d76b2f1.

* Revert "Auto-Register Commands in `routes/console.php` (#52867)"

This reverts commit e216708.
@crynobone
Copy link
Member

@SamuelNitsche this PR has been reverted due to breaking change with existing application.

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.

5 participants