Move duplicate logic into its own function
This commit is contained in:
parent
55c4159c87
commit
9e8325b437
1 changed files with 10 additions and 11 deletions
|
@ -49,13 +49,7 @@ class Media extends Model
|
||||||
*/
|
*/
|
||||||
public function getMediumurlAttribute()
|
public function getMediumurlAttribute()
|
||||||
{
|
{
|
||||||
$filenameParts = explode('.', $this->path);
|
$basename = $this->getBasename($this->path);
|
||||||
$extension = array_pop($filenameParts);
|
|
||||||
// the following acheives this data flow
|
|
||||||
// foo.bar.png => ['foo', 'bar', 'png'] => ['foo', 'bar'] => foo.bar
|
|
||||||
$basename = ltrim(array_reduce($filenameParts, function ($carry, $item) {
|
|
||||||
return $carry . '.' . $item;
|
|
||||||
}, ''), '.');
|
|
||||||
|
|
||||||
return config('filesystems.disks.s3.url') . '/' . $basename . '-medium.' . $extension;
|
return config('filesystems.disks.s3.url') . '/' . $basename . '-medium.' . $extension;
|
||||||
}
|
}
|
||||||
|
@ -67,14 +61,19 @@ class Media extends Model
|
||||||
*/
|
*/
|
||||||
public function getSmallurlAttribute()
|
public function getSmallurlAttribute()
|
||||||
{
|
{
|
||||||
$filenameParts = explode('.', $this->path);
|
$basename = $this->getBasename($this->path);
|
||||||
|
|
||||||
|
return config('filesystems.disks.s3.url') . '/' . $basename . '-small.' . $extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBasename($path)
|
||||||
|
{
|
||||||
|
$filenameParts = explode('.', $path);
|
||||||
$extension = array_pop($filenameParts);
|
$extension = array_pop($filenameParts);
|
||||||
// the following acheives this data flow
|
// the following achieves this data flow
|
||||||
// foo.bar.png => ['foo', 'bar', 'png'] => ['foo', 'bar'] => foo.bar
|
// foo.bar.png => ['foo', 'bar', 'png'] => ['foo', 'bar'] => foo.bar
|
||||||
$basename = ltrim(array_reduce($filenameParts, function ($carry, $item) {
|
$basename = ltrim(array_reduce($filenameParts, function ($carry, $item) {
|
||||||
return $carry . '.' . $item;
|
return $carry . '.' . $item;
|
||||||
}, ''), '.');
|
}, ''), '.');
|
||||||
|
|
||||||
return config('filesystems.disks.s3.url') . '/' . $basename . '-small.' . $extension;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue