Modifications
This commit is contained in:
parent
4bad426149
commit
4a3ecb3a61
|
@ -39,7 +39,6 @@ class BluescaleMailApi
|
|||
$notifiable_recipient = false;
|
||||
$notifiable_email = $notifiable->email;
|
||||
$recipients = $template->recipients;
|
||||
$attachments = $template->attachments;
|
||||
|
||||
if (count($recipients) > 0)
|
||||
foreach ($recipients as $recipient)
|
||||
|
@ -51,21 +50,40 @@ class BluescaleMailApi
|
|||
$template->recipients[] = [
|
||||
'address' => $notifiable->email
|
||||
];
|
||||
}
|
||||
|
||||
if (count($attachments) > 0) {
|
||||
$formatted_attachmments = [];
|
||||
foreach ($attachments as $attachment) {
|
||||
$file = new UploadedFile($attachment['path'], $attachment['filename'], 'application/octet-stream', null, null, false);
|
||||
$formatted_attachmments[] = $file;
|
||||
}
|
||||
$attachments = $template->attachments;
|
||||
if (count($attachments) > 0) { // Formatting attachments to UploadFiles
|
||||
$formatted_attachmments = [];
|
||||
foreach ($attachments as $attachment) {
|
||||
$formatted_attachmments[] = new UploadedFile($attachment['path'], $attachment['filename'], null, null, false);
|
||||
}
|
||||
|
||||
$template->attachments = $formatted_attachmments;
|
||||
$template->attachments = $formatted_attachmments;
|
||||
}
|
||||
|
||||
$multipart_form = [];
|
||||
|
||||
foreach($template as $key => $value){ // Formatting whole template to pass in 'multipart' form
|
||||
if(!is_array($value)){
|
||||
$multipart_form[] = ['name' => $key, 'contents' => $value];
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach($value as $multiKey => $multiValue){
|
||||
$multiName = $key . '[' .$multiKey . ']' . (is_array($multiValue) ? '[' . key($multiValue) . ']' : '' ) . '';
|
||||
$data = ['name' => $multiName, 'contents' => (is_array($multiValue) ? reset($multiValue) : $multiValue)];
|
||||
|
||||
if (substr($key, 0, 11) === "attachments")
|
||||
$data['filename'] = $multiValue->getClientOriginalName();
|
||||
|
||||
$multipart_form[] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return $client->request('post', $url, [
|
||||
'form_params' => $template,
|
||||
'multipart' => $multipart_form,
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . $this->api_key,
|
||||
'Accept' => 'application/json'
|
||||
|
|
Loading…
Reference in New Issue