From 307b496bad91af9dafd41f379d9f18fadc6af258 Mon Sep 17 00:00:00 2001 From: Paulo Castellano Date: Tue, 31 Mar 2026 22:13:04 -0300 Subject: [PATCH] fix: separate image/video upload limits (10MB/1GB), accept only MP4 video --- app/Http/Requests/App/Media/StoreMediaRequest.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/Http/Requests/App/Media/StoreMediaRequest.php b/app/Http/Requests/App/Media/StoreMediaRequest.php index 7e689055..5560b153 100644 --- a/app/Http/Requests/App/Media/StoreMediaRequest.php +++ b/app/Http/Requests/App/Media/StoreMediaRequest.php @@ -22,12 +22,14 @@ public function authorize(): bool public function rules(): array { + $maxSize = $this->isVideoUpload() ? 1048576 : 10240; // Videos: 1GB, Images: 10MB + return [ 'media' => [ 'required', 'file', - 'max:1048576', // 1GB - 'mimetypes:image/jpeg,image/png,image/gif,image/webp,video/mp4,video/quicktime,video/webm,application/pdf', + "max:{$maxSize}", + 'mimetypes:image/jpeg,image/png,image/gif,image/webp,video/mp4', ], 'model' => [ 'required', @@ -50,11 +52,16 @@ public function messages(): array { return [ 'media.required' => 'The file is required.', - 'media.max' => 'The file must be at most 1GB.', + 'media.max' => $this->isVideoUpload() ? 'Videos must be at most 1GB.' : 'Images must be at most 10MB.', 'media.mimetypes' => 'File type not supported.', 'model.required' => 'The model is required.', 'model.in' => 'Invalid model type.', 'model_id.required' => 'The model ID is required.', ]; } + + private function isVideoUpload(): bool + { + return str_starts_with($this->file('media')?->getMimeType() ?? '', 'video/'); + } }