Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fire Event or listener after certain time in Laravel

Tags:

php

laravel

Is it possible to Fire Event or listener after certain time in Laravel, my idea is to have one listener for sending mails after one minute, after user registration, cron isnt solution for this case.

like image 769
Vladimir Stus Avatar asked Jul 20 '16 12:07

Vladimir Stus


1 Answers

In this case a job would be a better options. To be honest queued jobs when firing logic within your application is more suited for this kind of logic.

Jobs require less set up to events as you only need a single class, rather than events and listeners.

To delay your job use the following syntax, where SendReminderEmail is your job. The parameter in the delay function is the number of seconds you wish to delay the process.

$job = (new SendReminderEmail($user))->delay(60);

https://laravel.com/docs/5.1/queues#delayed-jobs

like image 161
Gareth Drew Avatar answered Nov 16 '22 23:11

Gareth Drew