You can make a task available to Artisan and to your application in the app/Console/Kernel.php file.
The Kernel
class contains an array named $commands
which make your commands available to your application.
Add your command to this array, in order to make it available to Artisan and your application.
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
Commands\Inspire::class,
Commands\MyTaskName::class // This line makes MyTaskName available
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
}
}
Once this is done, you can now access your command via the command line, using Artisan. Assuming that your command has the $signature
property set to my:task
, you can run the following command to execute your task:
php artisan my:task