Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

noblemfd's avatar

How to schedule cron jobs

I have set this cron job for 1:00

     $schedule->command('updatecreatemanagerroles')
              ->dailyAt('01:00'); 

How do I reschedule it for:

4 times a day - 8 AM, 12 NOON, 4PM and 8PM

and it should run daily

Thank you

0 likes
9 replies
MichalOravec's avatar
$schedule->command('updatecreatemanagerroles')->dailyAt('08:00'); 

$schedule->command('updatecreatemanagerroles')->dailyAt('12:00'); 

$schedule->command('updatecreatemanagerroles')->dailyAt('16:00'); 

$schedule->command('updatecreatemanagerroles')->dailyAt('20:00');
1 like
tykus's avatar

You can use CRON expression;

$schedule->command('updatecreatemanagerroles')
	->cron('0 8,12,16,20 * *'); 
noblemfd's avatar

But the cron job is not running automatically until I run php artisan updatecreatemanagerroles

ElMarkesDeSade's avatar

Once you set your scheduled tasks in your Laravel kernel file then in the server you're using to host your application you have to put this in the cron file:

* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

Basically it will run the 'php artisan schedule:run' command every minute and depending on the execution configuration of your scheduled tasks they will be executed or not.

Snapey's avatar

@Destiny12

crontab -e -u www-data

replace www-data with the name of the user account that your web server runs under

martingray's avatar

Protected function schedule(Schedule $schedule) {

$schedule->command(‘sms:gudmorning’)->daily();

}

-- If we want to run tasks every hour every day.

$schedule->command(‘Task’)

->hourly();

For example, if you want to run a task daily at 11.30 then

$schedule->command(‘Task’)

->dailyAt(‘11.30’);

1 like
Snapey's avatar

@martingray i marked your answer as spam, hopefully others will do the same

what's the point of just reiterating what is written in the docs?

Please or to participate in this conversation.