Notifiable

This commit is contained in:
Loann 2020-04-29 18:02:40 +02:00
parent d59c5aa622
commit b2fcefb7ec
2 changed files with 19 additions and 2 deletions

View File

@ -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,

View File

@ -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);
}
}