Some users have another email address that is stored as secondary_email
column in users
table.
How to send Notification using $user->notify()
to this secondary email address?
You would override the toMail
method of your notification. For example:
use App\Mail\InvoicePaid as Mailable;
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return Mailable
*/
public function toMail($notifiable)
{
return (new Mailable($this->invoice))
->to($this->user->secondary_email ?? $this->user->email);
}
You can read more about formatting notifications here .
you can define a routeNotificationForMail
method on the notifiable entity model
public function routeNotificationForMail($notification)
{
// Return email address only...
return $this->email_address;
// Return email address and name...
return [$this->email_address => $this->name];
}
and then modify the function to suit your need. laravel documentation notifications
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.