BLOG // April 28, 2022

Chain scheduled commands in Laravel

Laravel doesn't have a great way of chaining commands sequentially, but this can easily be overcome by making a single command that does the job. Lets assume you need to run "posts:import" and then "posts:publish" sequentially.

Create a new Command called PostsSchedule and put the following in the handle() function:

$this->call('posts:import');
$this->call('posts:publish');

You can call your new posts:schedule command from Console/Kernel.php in your app folder:

$schedule->command('posts:schedule')->onOneServer()->hourly()->runInBackground();

And now you have posts:import run, and then posts:publish run.

Comments

Subscribe to new articles

If you enjoy my content, consider subscribing. You will only receive new blog stories, no other email.

Work

Site

© 2022 Dave Blakey. All rights reserved.

Development, startup and tech tips from Gatsby to Laravel, Strapi to PHP.