From dec02f583afeee3241524dba16ed350ee8f3ebc8 Mon Sep 17 00:00:00 2001 From: gouki Date: Mon, 12 Oct 2026 08:58:19 +0000 Subject: [PATCH] feat(media): use legacy filepath structure for attachments via custom path generator --- app/Support/LegacyAttachmentPathGenerator.php | 39 +++++++++++++++++++ config/media-library.php | 4 +- 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 app/Support/LegacyAttachmentPathGenerator.php diff --git a/app/Support/LegacyAttachmentPathGenerator.php b/app/Support/LegacyAttachmentPathGenerator.php new file mode 100644 index 0000000..6ccbbee --- /dev/null +++ b/app/Support/LegacyAttachmentPathGenerator.php @@ -0,0 +1,39 @@ +getCustomProperty('legacy_filepath'); + if ($legacy) { + $legacy = ltrim($legacy, '/'); + $dir = dirname($legacy); + if ($dir !== '.') { + return $dir . '/'; + } + } + + return $media->id . '/'; + } + + public function getPathForConversions(Media $media): string + { + return $this->getPath($media) . 'conversions/'; + } + + public function getPathForResponsiveImages(Media $media): string + { + return $this->getPath($media) . 'responsive-images/'; + } +} diff --git a/config/media-library.php b/config/media-library.php index 04c97cd..b650e15 100644 --- a/config/media-library.php +++ b/config/media-library.php @@ -155,9 +155,7 @@ return [ * Here you can specify which path generator should be used for the given class. */ 'custom_path_generators' => [ - // Model::class => PathGenerator::class - // or - // 'model_morph_alias' => PathGenerator::class + \App\Models\Post::class => \App\Support\LegacyAttachmentPathGenerator::class, ], /*