How to register a command via action without using the Console/Kernel.php
file, because it does not exist in Laravel 11
.
I executed the command
composer requires laravel/tinker
php artisan vendor:publish --provider="Laravel\Tinker\TinkerServiceProvider"
and in config/tinker.php
:
'commands' => [
\App\Actions\SitemapGenerateAction::class,
],
here is the action
use AsAction, AsCommand;
public string $commandSignature = 'sitemap:generate';
public string $commandDescription = 'Generate the sitemap';
protected array $sitemapData;
public function handle(): void
{
...
}
public function asCommand(Command $command): void
{
...
}
public function asController(): array
{
...
}
How to register a command via action without using the Console/Kernel.php file, because it does not exist in Laravel 11. I executed the command
In laravel 11 kernal.php
is no longer present.And the configuration should be made through bootstrap/app.php
file.
Task Scheduling,command registered is done through routes/console.php
in laravel 11.
For more detailed information you can check this link where you can define your command in routes/console.php
.
https://laravel.com/docs/11.x/artisan#closure-commands
And to get a crystal clear view on changes made on Laravel 11 you can check this link.
https://laravel-news.com/laravel-11-directory-structure
After going through above two mentioned link,I think you will get a clear idea about how you should register and use command
I have even answered a similar answer on this platform. You may chek it as well.