Skip to content

Commit

Permalink
[11.x] Add fromUrl() to Attachment (#52688)
Browse files Browse the repository at this point in the history
* [11.x] Add `fromUrl()` to Attachment

* CS Fixes

* formatting

---------

Co-authored-by: Tim MacDonald <[email protected]>
  • Loading branch information
KennedyTedesco and timacdonald authored Sep 11, 2024
1 parent d9c322d commit dcb8163
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Illuminate/Mail/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ public static function fromPath($path)
return new static(fn ($attachment, $pathStrategy) => $pathStrategy($path, $attachment));
}

/**
* Create a mail attachment from a URL.
*
* @param string $url
* @return static
*/
public static function fromUrl($url)
{
return static::fromPath($url);
}

/**
* Create a mail attachment from in-memory data.
*
Expand Down
29 changes: 29 additions & 0 deletions tests/Mail/AttachableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,33 @@ public function toMailAttachment()
99,
], $notification->dataArgs);
}

public function testFromUrlMethod()
{
$mailable = new class extends Mailable
{
public function build()
{
$this->attach(new class implements Attachable
{
public function toMailAttachment()
{
return Attachment::fromUrl('https://example.com/file.pdf')
->as('example.pdf')
->withMime('application/pdf');
}
});
}
};

$mailable->build();

$this->assertSame([
'file' => 'https://example.com/file.pdf',
'options' => [
'as' => 'example.pdf',
'mime' => 'application/pdf',
],
], $mailable->attachments[0]);
}
}

0 comments on commit dcb8163

Please sign in to comment.