Scheduled command on specific environments

Running Laravel scheduled command on specific environments.

1// Not good
2if (app()->environment('production', 'staging')) {
3 $schedule->command('emails:send')
4 ->daily();
5}
6// Better
7$schedule->command('emails:send')
8 ->daily()
9 ->onEnvironment(['production', 'staging']);

Tip given by @nguyenduy4994

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord