'required|string|min:1|max:255', 'lastname' => 'required|string|min:1|max:255', 'email' => 'required|email:rfc,dns,spoof,filter|max:255', 'password' => [ 'required', 'max:255', Password::min(8) ->mixedCase() ->letters() ->numbers() ->symbols() ->uncompromised() ], 'birth_date' => 'required|date_format:Y-m-d|max:255', 'address' => 'sometimes|required_with:address2|string|max:255', 'address2' => 'sometimes|string|max:255', 'phone' => ['sometimes', 'string', 'phone:' . ($this->currentCountry ? $this->currentCountry->iso : implode(',', Country::getValidIsoAplha2Codes()))], 'country' => [ 'sometimes', 'numeric', new EnumIsValidRule(Country::class), sprintf( 'in:%s', implode(',', Country::getValidCountries()) ) ], 'city' => 'sometimes|string|min:2|max:255', 'postcode' => ['sometimes', 'string', 'postal_code:' . ($this->currentCountry ? $this->currentCountry->iso : implode(',', Country::getValidIsoAplha2Codes()))], 'opt_in' => 'required|boolean', ]; } /** * Prepare the data for validation. * * @return void */ protected function prepareForValidation(): void { try { if (is_array($this->country)) { $this->currentCountry = Country::make(\intval($this->country)); } } catch (\TypeError | \BadMethodCallException $e) { $this->currentCountry = null; } parent::prepareForValidation(); } /** * Messages * * @return array */ public function messages() { return [ // phpcs:ignore Generic.Files.LineLength.TooLong 'phone.phone' => trans('Le champ :attribute est invalide, il accepte les numéros des pays suivants :countries.', [ 'countries' => implode(',', Country::getValidCountriesLabel()) ]), // phpcs:ignore Generic.Files.LineLength.TooLong 'country.in' => trans('Le champ :attribute est invalide, il accepte les pays suivants :countries.', [ 'countries' => implode(',', Country::getValidCountriesLabel()) ]) ]; } }