Laravel - adding tasks to cron | Create command and schedule tasks

1. Create a file to run your tasks with this command:

    
        php artisan make:command ExampleCommand
    

After executing this command, in the directory /app/Console/Commands appears your file called ExampleCommand.php

2. Open the ExampleCommand.php file and write your command in the
protected $signature field like this:

    
        protected $signature = 'email_notify:send';
    

Now you can run this command directly from the console like this:

    
        php artisan email_notify:send
    

This command will run the code inside the handle() method in the ExampleCommand.php file

3. To run this command on schedule, you need to add this command

    
        $schedule->command('email_notify:send')->everyMinute();
    

to the method schedule() in the Kernel.php which is located in /app/Console
Now you need add one command to your cron file. To do this, open your crontab with this command:
crontab -e and add this line to the end

    
        * * * * * cd /your_project_directory && php artisan schedule:run >/dev/null 2>&1
    

That's it! Your cron will run Kernel.php every minute,
and Kernel.php executes ExampleCommand.php
And for flexible schedule settings, you just need to change the everyMinute() method to other methods, for example, to everyFifteenMinutes() in the Kernel.php file