![](/img/trans.png)
[英]Laravel Notification only sends in one channel then does not detect the "toMail" method
[英]How to send notification through only one channel - Laravel 9
我需要使用 Web 推送和電子郵件向用戶發送通知,但在某些情況下可能會發現用戶沒有電子郵件地址,因此只能使用 Web 推送。 是否可以選擇應該通過哪個渠道發送通知,或者我是否必須為兩個渠道創建單獨的通知並僅在用戶具有分配的地址時才觸發電子郵件通知?
通知中的方法:
public function via($notifiable)
{
return [
MailChannel::class,
WebPushChannel::class,
];
}
public function toWebPush($notifiable, $notification)
{
return (new WebPushMessage)
->title('Twój profil jest aktywny')
->body('Administrator aktywował Twoje konto')
->data([
'type' => class_basename($this),
])
->options(['TTL' => 1000]);
}
public function toMail($notifiable)
{
return (new MailMessage)
->subject('Title..')
->line("Content...")
}
發送通知:
$user->notify(new UserActivation());
這就是via
方法的用途。 檢查那里的$notifiable->email
並返回適當的頻道
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.