laravel - Laravel 根据发送方法向不同的通知发送通知
问题描述
我有一个应用程序可以向管理员发送有关某些用户操作的通知。一些管理员应通过 SMS 通知,而其他管理员应仅通过数据库通知。做这个的最好方式是什么?使用两个通知还是只使用一个?我没有找到通过通知中的通知方法更改通知的任何方法。
有什么建议吗?
解决方案
它可以与 If 语句一起使用
class yourNotifName extends Notification
{
use Queueable;
private $role;
private $notif;
public function __construct(User $user)
{
$this->role= $user->role;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
if($this->role == "admins") {
$this->notif = ['sms'];
} else {
$this->notif = ['database'];
}
return $this->notif;
}
}
推荐阅读
- azure - 如何使用 ARM 模板`contentVersion`?
- excel-formula - 如果工作表 1 的列中的日期也在工作表 2 的列中,如何使用工作表 2 中的一行数据自动填充工作表 3?
- javascript - Jquery更改标签文本,引导程序
- excel - “日期”设置为一般,应设置为 DATES
- xslt - 需要帮助使用 XSLT 在 XML 中查找第一个非空元素
- java - 使用 Java 8 将日期字符串从“ddMMM”转换为“yyyy-MM-dd”
- rest - 使用 REST API 更新客户导致 500 内部服务器错误
- r - 在 Shiny Datatable 中选择并显示一行的值
- c# - 为什么我在此代码中遇到索引超出范围错误
- javascript - 尝试使用 javascript 在 Outlook for macOS 中保存 blob 文件