Skip to content

Commit dcb8163

Browse files
[11.x] Add fromUrl() to Attachment (#52688)
* [11.x] Add `fromUrl()` to Attachment * CS Fixes * formatting --------- Co-authored-by: Tim MacDonald <hello@timacdonald.me>
1 parent d9c322d commit dcb8163

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/Illuminate/Mail/Attachment.php

+11
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ public static function fromPath($path)
5555
return new static(fn ($attachment, $pathStrategy) => $pathStrategy($path, $attachment));
5656
}
5757

58+
/**
59+
* Create a mail attachment from a URL.
60+
*
61+
* @param string $url
62+
* @return static
63+
*/
64+
public static function fromUrl($url)
65+
{
66+
return static::fromPath($url);
67+
}
68+
5869
/**
5970
* Create a mail attachment from in-memory data.
6071
*

tests/Mail/AttachableTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,33 @@ public function toMailAttachment()
109109
99,
110110
], $notification->dataArgs);
111111
}
112+
113+
public function testFromUrlMethod()
114+
{
115+
$mailable = new class extends Mailable
116+
{
117+
public function build()
118+
{
119+
$this->attach(new class implements Attachable
120+
{
121+
public function toMailAttachment()
122+
{
123+
return Attachment::fromUrl('https://example.com/file.pdf')
124+
->as('example.pdf')
125+
->withMime('application/pdf');
126+
}
127+
});
128+
}
129+
};
130+
131+
$mailable->build();
132+
133+
$this->assertSame([
134+
'file' => 'https://example.com/file.pdf',
135+
'options' => [
136+
'as' => 'example.pdf',
137+
'mime' => 'application/pdf',
138+
],
139+
], $mailable->attachments[0]);
140+
}
112141
}

0 commit comments

Comments
 (0)