34 lines
902 B
PHP
34 lines
902 B
PHP
<?php
|
|
|
|
namespace App\Support\Media;
|
|
|
|
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
|
use Spatie\MediaLibrary\Support\PathGenerator\PathGenerator;
|
|
|
|
class ModulePathGenerator implements PathGenerator
|
|
{
|
|
public function getPath(Media $media): string
|
|
{
|
|
$module = $media->getCustomProperty('module', 'media');
|
|
$type = $media->getCustomProperty('type');
|
|
$date = $media->created_at?->format('Y-m-d') ?? now()->format('Y-m-d');
|
|
$id = $media->model_id;
|
|
|
|
if ($type) {
|
|
return "{$module}/{$type}/{$date}/{$id}/";
|
|
}
|
|
|
|
return "{$module}/{$date}/{$id}/";
|
|
}
|
|
|
|
public function getPathForConversions(Media $media): string
|
|
{
|
|
return $this->getPath($media).'conversions/';
|
|
}
|
|
|
|
public function getPathForResponsiveImages(Media $media): string
|
|
{
|
|
return $this->getPath($media).'responsive-images/';
|
|
}
|
|
}
|