Skip to content
Permalink
Browse files

Prevent duplicate attachments

This will prevent users from adding duplicate attachments. This bug surfaced when rendering a mailable for logging or storage before sending.
  • Loading branch information
taylorotwell committed Dec 17, 2019
1 parent 2cd9417 commit 3c8ccc2fb4ec03572076e6df71608f6bbb7d71e1
Showing with 12 additions and 4 deletions.
  1. +12 −4 src/Illuminate/Mail/Mailable.php
@@ -747,7 +747,10 @@ public function with($key, $value = null)
*/
public function attach($file, array $options = [])
{
$this->attachments[] = compact('file', 'options');
$this->attachments = collect($this->attachments)
->push(compact('file', 'options'))
->unique('file')
->all();

return $this;
}
@@ -776,12 +779,14 @@ public function attachFromStorage($path, $name = null, array $options = [])
*/
public function attachFromStorageDisk($disk, $path, $name = null, array $options = [])
{
$this->diskAttachments[] = [
$this->diskAttachments = collect($this->diskAttachments)->push([
'disk' => $disk,
'path' => $path,
'name' => $name ?? basename($path),
'options' => $options,
];
])->unique(function ($file) {
return $file['disk'].$file['path'];
})->all();

return $this;
}
@@ -796,7 +801,10 @@ public function attachFromStorageDisk($disk, $path, $name = null, array $options
*/
public function attachData($data, $name, array $options = [])
{
$this->rawAttachments[] = compact('data', 'name', 'options');
$this->rawAttachments = collect($this->rawAttachments)
->push(compact('data', 'name', 'options'))
->unique('data')
->all();

return $this;
}

0 comments on commit 3c8ccc2

Please sign in to comment.
You can’t perform that action at this time.