check(); } /** * Prepare the data for validation. * * @return void */ protected function prepareForValidation() { $this->merge([ 'button_status' => $this->boolean('button_status'), 'button_new_tab' => $this->boolean('button_new_tab') ]); if (intval($this->slider) !== \App\Enums\Slides\SliderTypeEnum::home->value()) { $this->merge([ 'video_id' => '' ]); }; $this->mergePicture('picture'); } /** * Get the validation rules that apply to the request. * * @return array */ public function rules(): array { $rules = [ 'slider' => [ 'required', new Enum(\App\Enums\Slides\SliderTypeEnum::class) ], 'title' => [ 'required_unless:slider,' . \App\Enums\Slides\SliderTypeEnum::home->value(), 'nullable', 'string', 'between:3,255' ], 'content' => 'required|string|between:3,255', 'video_id' => 'nullable|string|regex:%([^"&?\/\s]{11})%i', 'picture_alt' => 'required|string|between:3,255', 'picture_title' => 'required|string|between:3,255', 'button_label' => 'required_if:button_status,true|nullable|string|between:3,35', 'button_url' => 'required_if:button_status,true|nullable|string|between:3,255', 'button_status' => 'required|boolean', 'button_new_tab' => 'required|boolean', ]; return \array_merge( $rules, // FIXME: Mettre à jour les tailles. $this->pictureRules('picture', 100, 100, 100, 100, false), ); } /** * Get custom attributes for validator errors. * * @return array */ public function attributes(): array { return [ 'video_id' => trans('validation.custom.video_id'), ]; } /** * Custom validaton messages. * * @return array */ public function messages() { return [ 'title' => [ 'required_unless' => __('Le champ titre est obligatoire si le slider n\'est pas home.'), ] ]; } }