65 lines
1.5 KiB
PHP
65 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Settings;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class ProfileUpdateRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$supportedLocales = collect(explode(',', (string) env('APP_SUPPORTED_LOCALES', 'de,en')))
|
|
->map(fn ($l) => trim((string) $l))
|
|
->filter()
|
|
->unique()
|
|
->values()
|
|
->all();
|
|
|
|
if (empty($supportedLocales)) {
|
|
$supportedLocales = array_values(array_unique(array_filter([
|
|
config('app.locale'),
|
|
config('app.fallback_locale'),
|
|
])));
|
|
}
|
|
|
|
return [
|
|
'name' => ['required', 'string', 'max:255'],
|
|
|
|
'email' => [
|
|
'required',
|
|
'string',
|
|
'lowercase',
|
|
'email',
|
|
'max:255',
|
|
Rule::unique(User::class)->ignore($this->user()->id),
|
|
],
|
|
|
|
'username' => [
|
|
'nullable',
|
|
'string',
|
|
'max:32',
|
|
Rule::unique(User::class)->ignore($this->user()->id),
|
|
],
|
|
|
|
'preferred_locale' => [
|
|
'nullable',
|
|
'string',
|
|
Rule::in($supportedLocales),
|
|
],
|
|
];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|