*/ public const AUDIO_EXTENSIONS = [ 'mp3', 'mpeg', 'mpga', 'wav', 'ogg', 'oga', 'flac', 'm4a', 'mp4', 'aac', 'webm', 'wma', 'aiff', 'aif', ]; /** * Maximum upload size accepted by validation (2 GiB). */ public const MAX_AUDIO_KILOBYTES = 2 * 1024 * 1024; public function authorize(): bool { return $this->user() !== null; } /** * Normalize a single file upload into an array for batch handling. */ protected function prepareForValidation(): void { if ($this->hasFile('audio') && $this->file('audio') instanceof UploadedFile) { $this->files->set('audio', [$this->file('audio')]); } } /** * @return array */ public function rules(): array { return [ 'audio' => ['required', 'array', 'min:1', 'max:50'], 'audio.*' => [ 'required', File::types(self::AUDIO_EXTENSIONS)->max('2gb'), ], 'title' => ['nullable', 'string', 'max:255'], ]; } /** * @return array */ public function messages(): array { return [ 'audio.required' => 'Please choose at least one audio file to upload.', 'audio.min' => 'Please choose at least one audio file to upload.', 'audio.max' => 'You can upload at most 50 files at once.', 'audio.*.required' => 'Please choose an audio file to upload.', 'audio.*' => 'Unsupported audio type. Use MP3, WAV, OGG, FLAC, M4A, AAC, WebM, WMA, or AIFF.', 'audio.*.max' => 'Each audio file may not be larger than 2 GB.', ]; } }