[ 'sometimes', 'string', 'min:3', 'max:32', 'regex:/^[a-zA-Z0-9_.-]+$/', Rule::unique('users', 'name')->ignore($this->user()), ], 'bio' => ['sometimes', 'nullable', 'string'], 'locale' => ['sometimes', 'string', Rule::in(config('app.supported_locales', ['fr', 'en']))], 'avatar' => ['sometimes', 'nullable', 'image', 'max:2048'], ]; } public function after(): array { return $this->moderationChecks( [$this->input('name'), $this->input('bio')], [$this->file('avatar')], ); } 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]; } }