diff --git a/Modules/Video/Models/Video.php b/Modules/Video/Models/Video.php index bd68caf4c..4f5cb851c 100644 --- a/Modules/Video/Models/Video.php +++ b/Modules/Video/Models/Video.php @@ -94,7 +94,7 @@ class Video extends Model public static function createFromTemporaryUpload(Listing $listing, TemporaryUploadedFile $file, array $attributes = []): self { - $disk = (string) config('video.disk', MediaStorage::activeDisk()); + $disk = (string) ($attributes['disk'] ?? config('video.disk', MediaStorage::activeDisk())); $path = $file->storeAs( trim((string) config('video.upload_directory', 'videos/uploads').'/'.$listing->getKey(), '/'), Str::ulid().'.'.($file->getClientOriginalExtension() ?: $file->guessExtension() ?: 'mp4'), @@ -117,7 +117,7 @@ class Video extends Model public static function createFromUploadedFile(Listing $listing, UploadedFile $file, array $attributes = []): self { - $disk = (string) config('video.disk', MediaStorage::activeDisk()); + $disk = (string) ($attributes['disk'] ?? config('video.disk', MediaStorage::activeDisk())); $path = $file->storeAs( trim((string) config('video.upload_directory', 'videos/uploads').'/'.$listing->getKey(), '/'), Str::ulid().'.'.($file->getClientOriginalExtension() ?: $file->extension() ?: 'mp4'), diff --git a/app/Livewire/PanelQuickListingForm.php b/app/Livewire/PanelQuickListingForm.php index c8192de86..a545e9fbb 100644 --- a/app/Livewire/PanelQuickListingForm.php +++ b/app/Livewire/PanelQuickListingForm.php @@ -17,6 +17,7 @@ use Modules\Listing\Support\ListingCustomFieldSchemaBuilder; use Modules\Listing\Support\ListingPanelHelper; use Modules\Location\Models\City; use Modules\Location\Models\Country; +use Modules\S3\Support\MediaStorage; use Modules\User\App\Models\Profile; use Modules\Video\Models\Video; use Throwable; @@ -570,6 +571,7 @@ class PanelQuickListingForm extends Component ]; $listing = Listing::createFromFrontend($payload, $user->getKey()); + $mediaDisk = $this->frontendMediaDisk(); foreach ($this->photos as $photo) { if (! $photo instanceof TemporaryUploadedFile) { @@ -579,7 +581,7 @@ class PanelQuickListingForm extends Component $listing ->addMedia($photo->getRealPath()) ->usingFileName($photo->getClientOriginalName()) - ->toMediaCollection('listing-images'); + ->toMediaCollection('listing-images', $mediaDisk); } foreach ($this->videos as $index => $video) { @@ -588,6 +590,7 @@ class PanelQuickListingForm extends Component } Video::createFromTemporaryUpload($listing, $video, [ + 'disk' => $mediaDisk, 'sort_order' => $index + 1, 'title' => pathinfo($video->getClientOriginalName(), PATHINFO_FILENAME), ]); @@ -746,6 +749,11 @@ class PanelQuickListingForm extends Component return collect($this->categories)->contains(fn (array $category): bool => $category['id'] === $categoryId); } + private function frontendMediaDisk(): string + { + return (string) config('media_storage.local_disk', MediaStorage::diskFromDriver(MediaStorage::DRIVER_LOCAL)); + } + private function categoryPathParts(int $categoryId): array { $byId = collect($this->categories)->keyBy('id');