Notifiable
This commit is contained in:
parent
d59c5aa622
commit
b2fcefb7ec
|
@ -21,15 +21,32 @@ class BMailApi
|
|||
|
||||
/**
|
||||
* @param $template
|
||||
* @param $notifiable
|
||||
* @return \Psr\Http\Message\StreamInterface
|
||||
* @throws BMailException
|
||||
*/
|
||||
public function send($template): StreamInterface
|
||||
public function send($template, $notifiable): StreamInterface
|
||||
{
|
||||
$url = config('bmail.api_url');
|
||||
|
||||
$client = new Client();
|
||||
|
||||
$notifiable_recipient = false;
|
||||
if (is_object($notifiable) && $notifiable_email = $notifiable->email) {
|
||||
$recipients = $template->recipients;
|
||||
|
||||
if (count($recipients) > 0)
|
||||
foreach ($recipients as $recipient)
|
||||
if (!empty($recipient['address']))
|
||||
if ($notifiable_email == $recipient['address'])
|
||||
$notifiable_recipient = true;
|
||||
}
|
||||
|
||||
if (!$notifiable_recipient)
|
||||
$template->recipients[] = [
|
||||
'address' => $notifiable->email
|
||||
];
|
||||
|
||||
try {
|
||||
return $client->request('post', $url, [
|
||||
'form_params' => $template,
|
||||
|
|
|
@ -17,6 +17,6 @@ class BMailChannel
|
|||
{
|
||||
$template = $notification->toTemplate($notifiable);
|
||||
|
||||
return (new BMailApi(config("bmail.api_key")))->send($template);
|
||||
return (new BMailApi(config("bmail.api_key")))->send($template, $notifiable);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue