Laravel Notification - via specified by user

181 Views Asked by At

How can the method via in a notification class can be dinamic by the users preferences, one user maybe want to receive via email, the other one, dont

public function via($notifiable) {
    return ['database', 'broadcast', 'mail'];
}
1

There are 1 best solutions below

0
On BEST ANSWER

That function is receiving the User ($notifiable) as a parameter, you could call a method on the $notifiable to retrieve the list of channels you want the notification to use.

public function via($notifiable) {
    return $notifiable->getNotificationPreferences();
}