authService->check(); } #[\Override] protected function prepareForValidation() { $this->merge([ 'opt_in' => $this->boolean('opt_in'), ]); } public function toUpdateCustomerInput(): UpdateCustomerInput { return new UpdateCustomerInput( firstname: $this->string('firstname')->value(), lastname: $this->string('lastname')->value(), birthDate: $this->string('birth_date')->value(), phone: ! $this->string('phone')->isEmpty() ? $this->string('phone')->value() : null, city: $this->string('city')->value(), postcode: $this->string('postcode')->value(), address: ! $this->string('address')->isEmpty() ? $this->string('address')->value() : null, optIn: $this->boolean('opt_in'), ); } /** @return array */ public function rules(): array { $majorityDate = Date::now()->subYears(18)->format('Y-m-d'); return [ 'firstname' => ['required', 'string', 'max:255'], 'lastname' => ['required', 'string', 'max:255'], 'birth_date' => [ 'required', 'date', 'date_format:Y-m-d', 'before_or_equal:' . $majorityDate, ], 'address' => ['nullable', 'string', 'max:255'], 'phone' => ['nullable', 'phone:FR'], 'city' => ['required', 'string', 'max:255'], 'postcode' => ['required', 'postal_code:FR'], 'opt_in' => ['boolean'], ]; } /** @return array */ #[\Override] public function messages(): array { return [ 'birth_date.before_or_equal' => trans('validation.custom.birth_date.before_or_equal'), 'birth_date.date' => trans('validation.custom.birth_date.date'), 'birth_date.date_format' => trans('validation.custom.birth_date.date_format'), ]; } /** @return array */ #[\Override] public function attributes(): array { return [ 'firstname' => trans('validation.attributes.first_name'), 'lastname' => trans('validation.attributes.last_name'), 'birth_date' => trans('validation.attributes.date_of_birth'), 'address' => trans('validation.custom.attributes.postal_address'), 'phone' => trans('validation.attributes.phone'), 'city' => trans('validation.attributes.city'), 'postcode' => trans('validation.attributes.postal_code'), ]; } }