Imagine that you have a subscription-based application built with Laravel, and you want to send daily emails to all users, I don’t think you really like doing it manually. Checking for new users to copy the email addresses and send emails to them it’s boring and not productive, right? sure, 

And here comes the power of Cron jobs.

Cron jobs are powerful tools in any developer’s toolkit, they allow you to automate repetitive tasks and schedule them to run at specific intervals, freeing up your time to focus on other productive things, in Laravel 10, you can easily set up cron jobs using the artisan command-line, 

so In this tutorial, we will go through all the steps you should take to make sending emails automated with Laravel Cron Jobs in Laravel 10, we will see how to set up a cron job and schedule Tasks.


To make sure you get the best out of this tutorial you must have these prerequisites:

  • Basic understanding of PHP and Laravel,
  • Familiar with MVC architecture and routing in Laravel
  • Familiar with Laravel Artisan command
  • Understanding of basic database operations in Laravel.
  • Access to a server with Laravel 10 Installed.
  • Text Editor and a web browser.

Having these prerequisites will help you understand the concept and the steps covered in the tutorial more effectively.

Steps to create Cron Jobs Scheduling in Laravel:

  • Install Laravel Application
  • Setup Database
  • Create a Command Line 
  • Register Task Scheduler.
  • Run a Scheduler.
  • Scheduled Jobs on Live server.

1. Install Laravel Application:

 First of all, we need to download and set up a Laravel application. With composer installed on your computer, you can download and install Laravel via composer like so:

composer create-project laravel/laravel Newapp

Or you can install Laravel installer globally with the following command:

composer global require laravel/installer

And install Laravel on your local machine using the following command:

 laravel new Newapp

2. Setup Database

Now our Laravel Application is installed, we need to setup our database to store the data, head to the .env  file in the Laravel application, and modify the following: 


3. Create Command Line

 In order to create a command line, you must go inside the Laravel application we created 

cd /Newapp

Now you are in the app we can run the Artisan command like so:

php artisan make:command DailyEmails --daily:mails

This will create a new command class in the app/Console/Commands directory, let’s go to this file.

Here is how it looks:

namespace AppConsoleCommands;
use IlluminateConsoleCommand;
use IlluminateSupportFacadesHttp;
use Mail;
Use AppModelsUser;

class DailyEmails extends Command
    * The name and signature of the console command.
    * @var string
   protected $signature = 'daily:mails';

    * The console command description.
    * @var string
   protected $description = 'Command description';

    * Create a new command instance.
    * @return void
   public function __construct()

    * Execute the console command.
    * @return mixed
   public function handle()
        info(" daily mailing running". now());
       $response = Http::get("");

        $users = $response->json();


        foreach($users as $key => $user)


            if(! User::where('email',$user['email'])->exists()){


                                'name'=> $user['name'],
                                'email' => $user['email'],
                                'Password' =>bcrypt('12345678')


        $recivers = User::all();

        foreach($recievers as $reciever){
            Mail::to($reciever->email)->send('Your email');

In case you’re wondering why We are using jsonplaceholder, it’s a free API tool we are using to generate users and save them on our database.

4. Register Task Scheduler

In this step we need to register our new command in the kernel.php file and define the time when we need the command to run:

namespace AppConsole;
use IlluminateConsoleSchedulingSchedule;
use IlluminateFoundationConsoleKernel as ConsoleKernel;
use IlluminateSupportFacadesDB;
class Kernel extends ConsoleKernel
    * Define the application's command schedule.
    * @param  IlluminateConsoleSchedulingSchedule  $schedule
    * @return void
   protected function schedule(Schedule $schedule)
 protected function commands()
       Return base_path('routes/console.php');

5. Run a Scheduler:

Now we can test our cron, we can manually check using the following command of our cron, so let’s run it:

php artisan schedule:run

check our storage/logs/laravel.php file you will notice some logs like so:

[2022-03-01 03:51:02] local.INFO: daily mailing running at 2022-03-01 03:51:02

In my case, I Scheduled the command using the daily( ) option which Run the task every day at midnight here the command will run in 7 hours from now as shown below, when to see the scheduled tasks, you need to run the following command:

php artisan schedule:list
Laravel 9 Cron Jobs
task queries

6. Scheduled Jobs on the Live server

To schedule Jobs on a live server we need to install crontab, assuming you are using an ubuntu server so it’s already installed, we can run the following command and add a new entry for our cron job:

crontab -e

Now, let’s add the following line to the crontab file, you need to set the Laravel app path correctly on it.

cd /path/to/your/laravel/project && php artisan schedule:run >> /dev/null 2>&1

this line will add a single cron configuration entry to our server that runs the  schedule:run command every time based on the interval we choose here it runs every day at midnight.


Cron jobs in Laravel are a very powerful tool and flexible, they allow you to automate tasks and perform them at regular time intervals (daily – hourly … etc), freeing up your time to focus on other tasks, some of the key benefits of using cron jobs in Laravel:

  • 1  Task scheduling: you can schedule tasks to run automatically at a specific time, without manual intervention.
  • 2  Time-saving: Automating tasks using cron jobs saves time and reduces manual efforts.
  • 3  Increase efficiency:  By automating tasks, you can increase the efficiency of your application and ensure that tasks are completed on time.

In short, cron jobs in Laravel offer a powerful and flexible way to automate tasks and make the most of your time and resources. whether you need to send emails, generate reports, or perform other routine tasks, cron jobs in Laravel are a powerful tool for achieving your goals.