mergePicture('picture'); } /** * Get the validation rules that apply to the request. * * @return array|string> */ public function rules(): array { $width = (int) ($this->input('picture_width') ?: Picto::MIN_WIDTH); $height = (int) ($this->input('picture_height') ?: Picto::MIN_HEIGHT); $rules = [ 'title' => 'required|string|between:3,255', 'description' => ['nullable', 'string', new WysiwygLength(5)], 'picture_alt' => 'required_with:picture|nullable|between:3,255', 'picture_title' => 'required_with:picture|nullable|between:3,255', 'url' => 'nullable|url|between:3,255', 'section_id' => 'required|exists:section_pages,id', ]; return array_merge( $rules, $this->pictureRules('picture', $width, $height, $width, $height) ); } /** * Get custom attributes for validator errors. * * @return array */ public function attributes() { return [ 'title' => trans('validation.attributes.title'), 'description' => trans('validation.attributes.description'), 'picture' => trans('validation.attributes.image'), 'picture_alt' => trans('validation.custom.attribute_alt'), 'picture_title' => trans('validation.custom.attribute_title'), 'url' => trans('validation.custom.url'), ]; } protected function failedValidation(Validator $validator) { $errors = collect($validator->errors()->all())->join("\n"); session()->flash('error', 'Liste des erreurs :' . "\n" . $errors); throw new HttpResponseException( response()->json([ 'message' => 'Erreur de validation.', 'errors' => $validator->errors(), ], 422) ); } }