一定时间后在Laravel触发事件或听众

编程入门 行业动态 更新时间:2024-10-11 13:22:52
本文介绍了一定时间后在Laravel触发事件或听众的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否有可能在一定时间后在Laravel中触发事件或侦听器,我的想法是在用户注册后,有一个侦听器在一分钟后发送邮件,这种情况下cron不是解决方案.

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.

推荐答案

在这种情况下,工作将是一个更好的选择.老实说,在应用程序中触发逻辑时,排队的工作更适合这种逻辑.

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.

要延迟您的工作,请使用以下语法,其中SendReminderEmail是您的工作.延迟功能中的参数是您希望延迟该过程的秒数.

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);

laravel/docs/5.1/queues#delayed-jobs

更多推荐

一定时间后在Laravel触发事件或听众

本文发布于:2023-11-27 13:20:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638242.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:听众   事件   时间   Laravel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!