我正在创建 Laravel 网站。我需要那个用户(已登录)应该只能为他设置提醒。例如,他选择他的票到期日期为 2019-06-11,并且在 2 天之前他收到票即将到期的通知/提醒。怎么做? 谢谢。
最佳答案
你应该看看Task Scheduling在 Laravel 中。然后在您的 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 .
关于php - 如何在 Laravel 中为用户创建提醒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56168059/