-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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] After Laravel 11.24.0 commands in app/Console/Commands
are not auto-registered
#52902
Comments
One solution, is to always auto-register commands in public function withCommands(array $commands = [])
{
if (empty($commands) && is_file($this->app->basePath('routes/console.php'))) {
$commands = [...$commands, $this->app->basePath('routes/console.php')];
}
// CHANGED: remove the empty() check in this if clause
if (is_dir($this->app->path('Console/Commands'))) {
$commands = [...$commands, $this->app->path('Console/Commands')];
}
$this->app->afterResolving(ConsoleKernel::class, function ($kernel) use ($commands) {
[$commands, $paths] = collect($commands)->partition(fn ($command) => class_exists($command));
[$routes, $paths] = $paths->partition(fn ($path) => is_file($path));
$this->app->booted(static function () use ($kernel, $commands, $paths, $routes) {
$kernel->addCommands($commands->all());
$kernel->addCommandPaths($paths->all());
$kernel->addCommandRoutePaths($routes->all());
});
});
return $this;
} |
ping @taylorotwell @driesvints |
@rodrigopedra Sorry, that's my bad. I created a PR to fix this. |
Don't worry =) No production servers were harmed. At least not on my deployment =) I rushed to let them know as I imagine it could break some people's apps that depend on scheduled commands, or have a crontab calling any custom command directly |
After the release of the new version, I found that my Commands were invalid, I wrote them all in App\Console\Commands, and it was all such a coincidence My own temporary solution: register commands by providing the command's class name to the withCommands method
Fortunately, everything found in the development environment.Wait for specific solutions ^.^ |
My project has also problems with the same thing. |
You can add the following to
|
Can confirm this 👍 |
yup got this issue |
@SamuelNitsche shoudn't a fix contain a test case for this bug? |
Ideally the whole ApplicationBuilder itself would be covered by tests. However this isn't the case and I unfortunately wasn't sure how to properly test this. I guess Taylor wasn't sure either while developing it. |
i think this case should be covered with integration test somewhere in https://github.com/laravel/framework/tree/11.x/tests/Integration/Console |
Add this in bootstrap/app: |
So... it was reverted and it is not fixed?? Should this be reopend? |
Yes it was fixed |
I think not: click on the PR, scroll down... read: "this PR has been reverted due to breaking change with existing application." |
Any update on this? I've tried couple of solutions for this problem suggested here but I can't make it work, my commands are still not discovered by Laravel. |
Laravel Version
11.24.0
PHP Version
8.2.23
Database Driver & Version
mysql Ver 8.0.36 for Linux on x86_64 (MySQL Community Server - GPL)
Description
PR #52867 introduced a change to verify if the
routes/console.php
file exists. After this change, the commands inapp/Console/Commands
are not auto-registered anymore, if both theroutes/console.php
, and commands inapp/Console/Commands
exist.Steps To Reproduce
Public repo:
https://github.com/rodrigopedra/bug-report-laravel-11-24
Instructions are in the README
Previously, I was manually registering the
routes/console.php
fileThe text was updated successfully, but these errors were encountered: