Cron job in Laravel

Cron job in Laravel

In this tutorial we are going to see how to create cron job using Laravel. Cron job does not read the controller file, So we need to add cron job using commands.
Just 4 Steps to create Cron Job in Laravel.

STEP 1 :

Create Command in Laravel By using Below command.
Run the command in composer.

It will create the command File which is named as CronCommand inside the folder app/commands/CronCommand.php

CronCommand.php File code will like below.

STEP 2 : Simple “configuration” of CronCommand file:

You should change this line:

to something like this:

If you don’t need arguments, change this line:


And now pay attention to the fire function. The command will execute source code that is wrote in that function. Example:

 STEP #3: Register the command:

You need to register the command. So open app/start/artisan.php file, and add one line as below:

 STEP #4: Create CRON scheduled task:

Thats it, Now your command function will execute every 30 minutes.

If you like this article, Please don’t forget to share and comment.