merge([ 'type' => intval($this->route()->parameter('approach_type')), 'button_url' => intval($this->route()->parameter('approach_type')) === ApproachTypeEnum::demarche->value() ? $this->input('button_url') : null, 'published' => $this->boolean('published'), ]); $this->mergePicture('picture'); } /** * Get the validation rules that apply to the request. */ public function rules(): array { $rules = [ 'type' => ['required', new Enum(ApproachTypeEnum::class)], 'name' => 'required|string|between:3,255', 'picture_alt' => 'required_with:picture|nullable|between:3,255', 'picture_title' => 'required_with:picture|nullable|between:3,255', 'published' => 'required|boolean', ]; return \array_merge( $rules, ['button_url' => ($this->type === ApproachTypeEnum::demarche->value()) ? 'required|string|url' : 'nullable'], $this->pictureRules('picture', 100, 100, 100, 100), ); } /** * Get custom attributes for validator errors. */ public function attributes(): array { return [ 'name' => trans('validation.attributes.name'), 'picture' => trans('validation.attributes.image'), 'picture_alt' => trans('validation.custom.attribute_alt'), 'picture_title' => trans('validation.custom.attribute_title'), 'button_url' => trans('validation.custom.button_url'), 'published' => trans('validation.attributes.published'), ]; } }