File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments