Skip to content

Commit 3af7d9d

Browse files
committed
new config for file name
1 parent 6f2d9b2 commit 3af7d9d

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/Traits/HasPhotos.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/config/eloquent_photo.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
return [
44
'disk' => 'public',
5+
'name_attribute' => 'slug',
56
'root_directory' => 'images',
67
'quality' => 50,
78
'format' => 'webp',

0 commit comments

Comments
 (0)