|string> */ public function rules(): array { return [ 'name' => [ 'required', 'string', 'min:3', 'max:32', 'regex:/^[a-zA-Z0-9_.-]+$/', 'unique:users,name', ], 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], 'locale' => ['sometimes', 'string', Rule::in(config('app.supported_locales', ['fr', 'en']))], 'password' => ['required', 'string', 'min:8'], 'avatar' => ['sometimes', 'nullable', 'image', 'max:2048'], 'bio' => ['nullable', 'string'], 'physicalActivityLevel' => ['sometimes', Rule::enum(PhysicalActivityLevel::class)], 'weightGoal' => ['sometimes', Rule::enum(WeightGoal::class)], 'pacePreference' => ['sometimes', Rule::enum(PacePreference::class)], 'sex' => ['sometimes', Rule::enum(UserSex::class)], 'dateOfBirth' => ['sometimes', 'nullable', 'date_format:Y-m-d', 'before:today', 'after:1900-01-01'], 'date_of_birth' => ['sometimes', 'nullable', 'date_format:Y-m-d', 'before:today', 'after:1900-01-01'], ]; } public function messages(): array { return [ 'avatar.max' => __('api.validation.image_max_2mb'), ]; } protected function prepareForValidation(): void { if ($this->has('locale')) { $this->merge([ 'locale' => $this->normalizeLocale((string) $this->input('locale')), ]); } } private function normalizeLocale(string $locale): string { $locale = strtolower(str_replace('_', '-', $locale)); return explode('-', $locale)[0]; } }