feat: locale
This commit is contained in:
@@ -37,6 +37,7 @@ class RegisterRequest extends FormRequest
|
||||
'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'],
|
||||
@@ -56,4 +57,20 @@ class RegisterRequest extends FormRequest
|
||||
'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];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user