Skip to content

Commit 47974a8

Browse files
authored
Check for $file in attach and check for $data in attachData
Only add attachment data if the $file or $data are not empty
1 parent c91e98b commit 47974a8

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/EmailComposer.php

+16-4
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,15 @@ public function mailable(Mailable $mailable)
218218
*/
219219
public function attach($file, $options = [])
220220
{
221-
$attachments = $this->hasData('attachments') ? $this->getData('attachments') : [];
221+
$attachments = null;
222222

223-
$attachments[] = compact('file', 'options');
223+
if ( !empty($file) || !is_null($file) ) {
224+
225+
$attachments = $this->hasData('attachments') ? $this->getData('attachments') : [];
226+
227+
$attachments[] = compact('file', 'options');
228+
229+
}
224230

225231
return $this->setData('attachments', $attachments);
226232
}
@@ -235,9 +241,15 @@ public function attach($file, $options = [])
235241
*/
236242
public function attachData($data, $name, array $options = [])
237243
{
238-
$attachments = $this->hasData('rawAttachments') ? $this->getData('rawAttachments') : [];
244+
$attachments = null;
239245

240-
$attachments[] = compact('data', 'name', 'options');
246+
if ( !empty($data) || !is_null($data) ) {
247+
248+
$attachments = $this->hasData('rawAttachments') ? $this->getData('rawAttachments') : [];
249+
250+
$attachments[] = compact('data', 'name', 'options');
251+
252+
}
241253

242254
return $this->setData('rawAttachments', $attachments);
243255
}

0 commit comments

Comments
 (0)