From 4cd80eae10cadb30b79de7e91362aa3a35a70853 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Tue, 10 Mar 2026 12:46:10 +0700 Subject: [PATCH] feat: Implement CustomPathGenerator for dynamic media path generation in the Media Library. --- app/MediaLibrary/CustomPathGenerator.php | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 app/MediaLibrary/CustomPathGenerator.php diff --git a/app/MediaLibrary/CustomPathGenerator.php b/app/MediaLibrary/CustomPathGenerator.php new file mode 100644 index 0000000..3e51ffc --- /dev/null +++ b/app/MediaLibrary/CustomPathGenerator.php @@ -0,0 +1,40 @@ +getCustomProperty('feature', 'misc'); + $date = $media->getCustomProperty('date', now()->toDateString()); + $docType = $media->getCustomProperty('doc_type'); + + $feature = str($feature)->slug(); + $date = str($date); + $docType = $docType ? str($docType)->slug() : null; + + $path = "{$feature}/"; + + if ($docType) { + $path .= "{$docType}/"; + } + + $path .= "{$date}/"; + + return $path; + } + + public function getPathForConversions(Media $media): string + { + return $this->getPath($media).'conversions/'; + } + + public function getPathForResponsiveImages(Media $media): string + { + return $this->getPath($media).'responsive/'; + } +}