feat: locale
This commit is contained in:
@@ -21,6 +21,7 @@ class UpdateUserRequest extends FormRequest
|
||||
return [
|
||||
'bio' => ['sometimes', 'nullable', 'string'],
|
||||
'height' => ['sometimes', 'nullable', 'integer'],
|
||||
'locale' => ['sometimes', 'string', Rule::in(config('app.supported_locales', ['fr', 'en']))],
|
||||
'avatar' => ['sometimes', 'nullable', 'image', 'max:2048'],
|
||||
'nutritionGoals' => ['sometimes', 'array'],
|
||||
'nutritionGoals.calories' => ['required_with:nutritionGoals', 'integer', 'min:0', 'max:100000'],
|
||||
@@ -46,4 +47,20 @@ class UpdateUserRequest extends FormRequest
|
||||
'nutritionGoals.*.max' => __('api.validation.nutrition_goals_max'),
|
||||
];
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user