dstpabuaran.com/app/Media/PathGenerators/CustomPathGenerator.php
Yoga Pangestu a138ffe63c feat: add media library configuration and file upload components
- Added `media-library.php` configuration file for managing media uploads and conversions.
- Updated `filesystems.php` to set default visibility for AWS S3 storage.
- Implemented `FileUpload` component for handling file uploads with preview and error handling.
- Created `ImagePreviewModal` component for displaying image previews in a modal.
- Introduced `Attachment` UI components for better file attachment handling.
- Added `useFileUpload` hook to manage file upload state and logic.
- Implemented utility functions for uploading files to S3 with presigned URLs.
- Created API route for generating presigned URLs for file uploads.
2026-07-30 10:16:49 +07:00

40 lines
994 B
PHP

<?php
namespace App\Media\PathGenerators;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
use Spatie\MediaLibrary\Support\PathGenerator\PathGenerator;
class CustomPathGenerator implements PathGenerator
{
public function getPath(Media $media): string
{
$model = $media->model;
if (method_exists($model, 'getMediaPath')) {
return $model->getMediaPath($media).'/';
}
return $this->defaultPath($media);
}
public function getPathForConversions(Media $media): string
{
return $this->getPath($media).'conversions/';
}
public function getPathForResponsiveImages(Media $media): string
{
return $this->getPath($media).'responsive/';
}
private function defaultPath(Media $media): string
{
$module = strtolower(class_basename($media->model_type));
$date = $media->created_at->format('Y/m/d');
$id = $media->id;
return "{$module}/{$date}/{$id}/";
}
}