我正在创建Laravel网站。我需要用户(谁是登录)应该能够设置提醒只为他。例如,他选择他的票证到期日期是2019-06-11,在2天之前,他会收到通知/提醒,票证即将到期。如何做到这一点?谢谢。
发布于 2019-05-16 20:57:48
您应该关注Laravel中的Task Scheduling。然后在你的app/Console/Kernel.php文件中,你可以这样做:
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// This code will be scheduled for execution every day at 8:00 am.
$schedule->call(function () {
// Get all tickets that are about to expire in the next 2 days.
$tickets = \App\Ticket::whereBetween('expires_at', [now(), now()->addDays(2)])->get();
// Send notifications for those tickets owners.
$tickets->each(function ($ticket) {
$ticket->user->notify(new \App\Notifications\TicketExpirationReminder($ticket));
});
})->dailyAt('08:00');
}我给出的代码是你可以用来举例说明你所询问的事情是如何完成的。你也应该看看notifications can be set up in Laravel是怎么做到的。
https://stackoverflow.com/questions/56168059
复制相似问题