If you are trying to executing a periodic task on the server like for sending emails, database cleanup and generating reports. To automate these tasks We use Laravel cron jobs scheduling. This article is all about How To Schedule Jobs in Bagisto?
In Bagisto We can also achieve this by the following steps:
Step 1
You should be in the root folder of your application and run the following commands from your terminal:
php artisan make:command Command Name(userUpdate).
This command will create a new command class in the app/Console/Commands directory. In to this class you will find the following code in it and just Place this file to your packages Console/Commands directory:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<?php namespace App\Console\Commands; use Illuminate\Console\Command; class userUpdate extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'command:name'; /** * The console command description. * * @var string */ protected $description = 'Command description'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return mixed */ public function handle() { // } } |
Just change the name space of the command class according to your package.
Step 2
As you can see:
protected $signature = ‘command:name’;
Whatever you replace the words command:name with it will be used to execute the command that you have created before like:
protected $signature = ‘user:update’;
Step 3
write your code/logic in the handle method:
1 2 3 4 5 |
public function handle() { //do whatever you want to perform } |
Step 4
Register command in your package ServiceProvider’s Register method :
1 2 3 4 5 6 |
if ($this->app->runningInConsole()) { $this->commands([ userUpdate::class, ]); } |
Step 5
Now run the following command:
1 |
crontab -e |
Step 6
Add the following cron expression to the crontab for automatic User Update information:
1 |
30 * * * * php /project_root_forlder_path user:update && php artisan user:update |
You can also check your command by running : php artisan list.
In the above Cron expression(* * * * *) , each field is an option to determine task schedule frequency. These options represent minute, hour, day of the month, month and day of the week in the given order. Asterisk symbol means all possible values. So, the above command will run every 30 minutes.
So this was all about How To Schedule Jobs in Bagisto? hope it will be helpful for you. If you have any issue feel free to raise a ticket at https://bagisto.uvdesk.com/en/
reference : Laravel Cron Job