3

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'];
}
SpaceDogCS
  • 2,808
  • 3
  • 20
  • 49

1 Answers1

3

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();
}
brenjt
  • 15,997
  • 13
  • 77
  • 118