Laravel Task Scheduling Making a task available

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

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


Got any Laravel Question?