Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Ability to attach an array of files in MailMessage #43080

Merged
merged 8 commits into from Jul 22, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 18 additions & 12 deletions src/Illuminate/Mail/Mailable.php
Expand Up @@ -872,21 +872,27 @@ public function with($key, $value = null)
* @param array $options
* @return $this
*/
public function attach($file, array $options = [])
public function attach($files, array $options = [])
{
if ($file instanceof Attachable) {
$file = $file->toMailAttachment();
}

if ($file instanceof Attachment) {
return $file->attachTo($this);
if(!is_iterable($files)) {
$files = explode(',', $files);
timacdonald marked this conversation as resolved.
Show resolved Hide resolved
};

foreach ($files as $file) {
if ($file instanceof Attachable) {
$file = $file->toMailAttachment();
}

if ($file instanceof Attachment) {
return $file->attachTo($this);
}

$this->attachments = collect($this->attachments)
->push(compact('file', 'options'))
->unique('file')
->all();
}

$this->attachments = collect($this->attachments)
->push(compact('file', 'options'))
->unique('file')
->all();

return $this;
}

Expand Down