@@ -50,11 +50,13 @@ public function getPhotoFullPath(string $photoPath)
5050
5151 public function getPhotoDirectoryPath ()
5252 {
53+ $ nameAttribute = config ('eloquent_photo.name_attribute ' );
54+
5355 return config ('eloquent_photo.root_directory ' ) .
5456 '/ ' .
5557 $ this ->getDirName () .
5658 '/ ' .
57- str ($ this ->slug )
59+ str ($ this ->$ nameAttribute )
5860 ->limit (config ('eloquent_photo.slug_limit ' ))
5961 ->toString () .
6062 '_ ' .
@@ -70,15 +72,20 @@ public function getDirName(): string
7072 ->toString ();
7173 }
7274
73- public function __get ( $ key )
75+ public function __call ( $ method , $ parameters )
7476 {
75- if (str_starts_with ($ key , 'photo ' ) && str_ends_with ($ key , 'url ' )) {
76- $ photoField = str_replace ('url ' , '' , $ key );
77- return $ this ->$ photoField
78- ? Storage::disk (config ('eloquent_photo.disk ' ))->url ($ this ->$ photoField )
79- : null ;
77+ if (str_starts_with ($ method , 'get ' ) && str_contains ($ method , 'PhotoUrl ' ) && str_ends_with ($ method , 'Attribute ' )) {
78+
79+ $ photoField = str_replace (['get ' , 'UrlAttribute ' ], '' , $ method );
80+
81+ if (isset ($ this ->attributes [$ photoField ])) {
82+ return Storage::disk ('public ' )->url ($ this ->attributes [$ photoField ]);
83+ }
84+
85+ return null ;
8086 }
8187
82- return parent ::__get ( $ key );
88+ return parent ::__call ( $ method , $ parameters );
8389 }
90+
8491}
0 commit comments