1

I have configured it to send notifications to users who can be members or non-members.

Notifications are sent via email, database, and broadcast.

At this time, if the user is a member, he will receive a notification through e-mail, database, and broadcast, and if the user is a non-member, the user will receive a notification through e-mail.

If the user is a member, the code below is called.

User::find($userId)->notify($notificationInstance);

If the user is a non-member, the code below is called.

Notification::route('mail', $emailAddress)->notify($notificationInstance);

If the user is a member, it works as expected.

However, for non-members, it is transmitted through e-mail and broadcast. Why does broadcast work? Also, why are databases excluded?

dvlpr91
  • 11
  • 3
  • Hi, upon quick scan on the laravel documentation, I think `database` notification need to have a user, since its a non-member notify via database is not executed. You can see that in the `notifications` table you have `notifiable_type` and `notifiable_id` to be the users table and the id of the user. – aceraven777 May 31 '22 at 05:13
  • Thank you. But that's not the intent of my question. – dvlpr91 Jun 02 '22 at 00:05

1 Answers1

0
...

public function via($notifiable)
{
  if ($notifiable instanceof AnonymousNotifiable) {
    if (Arr::exists($notifiable->routes, 'mail')) {
      $via[] = 'mail';
    }

    if (...) {
      $via[] = '...';
    }
  
    return $via;
  }
}

...

Solved. Here my code.

dvlpr91
  • 11
  • 3