0

I'm trying to ->notify() different users of the same type via different notification methods. For example: I have TicketCompleted notification and its via() method contains: return ['mail', 'database'];. I also have both methods toArray() and toMail() implemented. So what I'm trying to do is the following:

Model Client that has role Accountant should be notified only via toArray() method;

Model Client that has role Contact should be notified only via toEmail() method;

How to achieve this?

1 Answer 1

1

You can return different values in via():

public function via($notifiable)
{
  if ($notifiable->role === 'Accountant') {
    return ['database'];
  } else if ($notifiable->role === 'Contact') {
    return ['mail'];
  }

  // default for all other clients
  return [];
}

If you use the same Notification for other models you also have to check the class of $notifiable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.