php - 如何在 Laravel 中为用户创建提醒

标签 php html css laravel

我正在创建 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/

相关文章:

php - 具有 Symfony 表单/实体字段名称 'from' 时出现问题

javascript - 仅在按下按钮时运行函数

javascript - 如果 hasClass 然后触发 mouseover mouseout

html - 横向导航让当前的li更高

css - 如何在 SASS mixin 中使用 !default?

html - 使用 Perl 正则表达式从 HTML 文件打印多行模式

PHP preg_match 使弯撇号与其他类型的弯引号不匹配。如何避免?

php - Laravel 5 从另一种方法重定向

php - 我想将两种形式插入数据库,一种用于创建表,另一种用于插入数据,但它不插入数据库

html - Respond.js 隐藏标志图像 ie8