authService->guest(); } #[\Override] public function prepareForValidation() { $this->merge([ 'optin' => $this->boolean('optin'), ]); } /** @return array{matricule:string,code:string,lastname:string,firstname:string,phone:string|null,address:string|null,postal_code:string,city:string,email:string,password:string,optin:bool,birth_date:\DateTimeImmutable} */ public function getFormData(): array { return [ 'matricule' => $this->string('matricule')->value(), 'code' => $this->string('code')->value(), 'lastname' => $this->string('lastname')->value(), 'firstname' => $this->string('firstname')->value(), 'phone' => $this->string('phone')->value(), 'address' => $this->string('address')->value(), 'postal_code' => $this->string('postal_code')->value(), 'city' => $this->string('city')->value(), 'email' => $this->string('email')->value(), 'password' => $this->string('password')->value(), 'optin' => $this->boolean('optin'), 'birth_date' => \DateTimeImmutable::createFromFormat( 'Y-m-d', $this->string('birth_date')->value() ) ?: throw new \InvalidArgumentException('Invalid birth date format'), ]; } /** @return array */ public function rules(): array { return [ 'matricule' => ['required', 'exists:employees,matricule'], 'code' => [ 'required', Rule::exists('employees', 'code') ->where('matricule', $this->string('matricule')->value()), ], 'lastname' => ['required', 'string', 'max:255'], 'firstname' => ['required', 'string', 'max:255'], 'phone' => ['sometimes', 'phone:FR', 'max:255'], 'address' => ['sometimes', 'max:255'], 'postal_code' => ['required', 'postal_code:FR'], 'city' => ['required', 'string', 'max:255'], 'email' => ['required', 'unique:customers,email', 'email:rfc,dns,spoof', 'max:255'], 'password' => [ 'required', 'required_with:password_confirmation', 'confirmed', 'max:255', Password::min(8) ->mixedCase() ->letters() ->numbers() ->symbols() ->uncompromised(), ], 'ok_cgv' => ['accepted'], 'optin' => ['sometimes', 'boolean'], 'birth_date' => ['required', new Adult()], ]; } /** @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.attributes.address'), 'phone' => trans('validation.attributes.phone'), 'city' => trans('validation.attributes.city'), 'postcode' => trans('validation.attributes.postal_code'), 'password' => trans('validation.attributes.password'), 'matricule' => trans('validation.attributes.matricule'), 'code' => trans('validation.attributes.code'), 'ok_cgv' => trans('validation.custom.attributes.ok_cgv'), 'optin' => trans('validation.custom.attributes.optin'), ]; } }