- 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.
40 lines
994 B
PHP
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}/";
|
|
}
|
|
}
|