【发布时间】:2021-04-24 11:16:41
【问题描述】:
我有一个应用程序可以向管理员发送有关某些用户操作的通知。一些管理员应通过 SMS 通知,而其他管理员应仅通过数据库通知。 做这个的最好方式是什么?使用两个通知还是只使用一个?我没有找到通过通知中的通知方法更改通知的任何方法。
有什么建议吗?
【问题讨论】:
标签: laravel notifications laravel-notification
我有一个应用程序可以向管理员发送有关某些用户操作的通知。一些管理员应通过 SMS 通知,而其他管理员应仅通过数据库通知。 做这个的最好方式是什么?使用两个通知还是只使用一个?我没有找到通过通知中的通知方法更改通知的任何方法。
有什么建议吗?
【问题讨论】:
标签: laravel notifications laravel-notification
它可以与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;
}
}
【讨论】: