77use Illuminate \Support \Collection ;
88use Illuminate \Support \Facades \Config ;
99use Illuminate \Support \Facades \Storage ;
10+ use Illuminate \Support \Str ;
1011use VanOns \LaravelAttachmentLibrary \Adapters \FileMetadata \MetadataAdapter ;
1112use VanOns \LaravelAttachmentLibrary \DataTransferObjects \Directory ;
1213use VanOns \LaravelAttachmentLibrary \DataTransferObjects \FileMetadata ;
@@ -95,14 +96,6 @@ protected function getFilesystem(): Filesystem
9596 return Storage::disk ($ this ->disk );
9697 }
9798
98- /**
99- * Return single file or null for given ID.
100- */
101- public function find (string |int $ id ): ?Attachment
102- {
103- return $ this ->attachmentClass ::find ($ id );
104- }
105-
10699 /**
107100 * Return files under a given path.
108101 *
@@ -121,6 +114,25 @@ public function file(string $path): ?Attachment
121114 return $ this ->attachmentClass ::whereDisk ($ this ->disk )->whereFilename (new Filename ($ path ))->first ();
122115 }
123116
117+ /**
118+ * Return single file or null for given ID.
119+ */
120+ public function find (string |int $ id ): ?Attachment
121+ {
122+ return $ this ->attachmentClass ::whereDisk ($ this ->disk )->find ($ id );
123+ }
124+
125+ /**
126+ * Return single file or null for given URL.
127+ */
128+ public function findByUrl (string $ url ): ?Attachment
129+ {
130+ $ baseUrl = Str::chopEnd (route ('attachment ' , ['attachment ' => 'PLACEHOLDER ' ]), 'PLACEHOLDER ' );
131+ $ path = Str::chopStart ($ url , $ baseUrl );
132+
133+ return $ this ->file ($ path );
134+ }
135+
124136 /**
125137 * Upload a file to the selected disk under the desired path and create a database entry.
126138 *
0 commit comments