Skip to content

Commit beb57de

Browse files
committed
fix: change functionality to support older laravel versions
1 parent c4294b8 commit beb57de

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/AttachmentManager.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,22 @@ public function find(string|int $id): ?Attachment
128128
*/
129129
public function findByUrl(string $url): ?Attachment
130130
{
131-
$baseUrl = Str::chopEnd(route('attachment', ['attachment' => 'PLACEHOLDER']), 'PLACEHOLDER');
132-
$path = Str::chopStart($url, $baseUrl);
131+
$placeholder = 'PLACEHOLDER';
132+
$baseUrlWithPlaceholder = route('attachment', ['attachment' => $placeholder]);
133+
134+
// Remove the placeholder suffix from the generated route URL.
135+
if (Str::endsWith($baseUrlWithPlaceholder, $placeholder)) {
136+
$baseUrl = substr($baseUrlWithPlaceholder, 0, -strlen($placeholder));
137+
} else {
138+
$baseUrl = $baseUrlWithPlaceholder;
139+
}
140+
141+
// Remove the base URL prefix from the provided URL to get the path.
142+
if (Str::startsWith($url, $baseUrl)) {
143+
$path = substr($url, strlen($baseUrl));
144+
} else {
145+
$path = $url;
146+
}
133147

134148
return $this->file($path);
135149
}

0 commit comments

Comments
 (0)