消息通知提醒 laravel notification

发布时间: 2019-05-08 10:09:59 作者: 大象笔记

参考 https://laravel.com/docs/5.5/notifications

创建提醒

php artisan make:notification InvoicePaid

app/Notifications 目录下会新增一个对应的 class

场景

单独发送消息 VS 群发消息

给指定用户发送

$user->notify(new InvoicePaid($invoice));

群发消息

Notification::send($users, new InvoicePaid($invoice));

通知的方式

通过 via 函数指定。

Database Notifications

建表

php artisan notifications:table
php artisan migrate

标记为已读

You may also use a mass-update query to mark all of the notifications as read without retrieving them from the database:

$user = App\User::find(1);
$user->unreadNotifications()->update(['read_at' => now()]);

消息队列

当单个事件触发的消息量巨大,例如,大 V 发twitter,大量粉丝需要接收消息。或者,消息需要调用三方 API 时,就需要用到队列。

我看 Laravel 支持的不错,能节省很大的工作量。

但是最终我还是选择自己实现

没有使用 Laravel 内置 Notification 的原因

我是一名山东烟台的开发者,联系作者