If you need precise scheduling for jobs in Laravel based on a timezone, there's a method for that.
Here's an example of running a named artisan command inside routes/console.php
.
Schedule::command('report:generate')
->at('2:00')
The ->at('2:00')
assumes the timezone of your Laravel application. How do we customise this if it needs to differ?
Just reach for the timezone
method.
Schedule::command('report:generate')
->timezone('America/New_York')
->at('2:00')
This method accepts any valid timezone as defined by PHP. You can find a list of valid timezones for PHP here.
If you need to change all scheduled tasks to a specific timezone, you can add the schedule_timezone
setting to your config/app.php
config file.
'schedule_timezone' => 'America/New_York',