Notifiable
This commit is contained in:
parent
d59c5aa622
commit
b2fcefb7ec
|
@ -21,15 +21,32 @@ class BMailApi
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $template
|
* @param $template
|
||||||
|
* @param $notifiable
|
||||||
* @return \Psr\Http\Message\StreamInterface
|
* @return \Psr\Http\Message\StreamInterface
|
||||||
* @throws BMailException
|
* @throws BMailException
|
||||||
*/
|
*/
|
||||||
public function send($template): StreamInterface
|
public function send($template, $notifiable): StreamInterface
|
||||||
{
|
{
|
||||||
$url = config('bmail.api_url');
|
$url = config('bmail.api_url');
|
||||||
|
|
||||||
$client = new Client();
|
$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 {
|
try {
|
||||||
return $client->request('post', $url, [
|
return $client->request('post', $url, [
|
||||||
'form_params' => $template,
|
'form_params' => $template,
|
||||||
|
|
|
@ -17,6 +17,6 @@ class BMailChannel
|
||||||
{
|
{
|
||||||
$template = $notification->toTemplate($notifiable);
|
$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