83 lines
2.3 KiB
PHP
83 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\AppUser;
|
|
|
|
use App\Enums\AppUserRolesEnum;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rules\Enum;
|
|
use Illuminate\Validation\Rules\Password;
|
|
|
|
class StoreAppUserRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return auth('backend')->check();
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'status' => $this->status ? true : false,
|
|
'authorizedFolders' => $this->authorizedFolders ? $this->authorizedFolders : [],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'lastname' => 'required|min:3|max:255',
|
|
'firstname' => 'required|min:3|max:255',
|
|
'email' => 'required|min:3|max:255|email:rfc,dns|unique:app_users,email',
|
|
'password' => [
|
|
'required',
|
|
'required_with:password_confirmation',
|
|
'confirmed',
|
|
'max:255',
|
|
Password::min(8)
|
|
->letters()
|
|
->mixedCase()
|
|
->numbers()
|
|
->symbols()
|
|
],
|
|
'authorizedFolders' => 'present|array',
|
|
'role' => [
|
|
'required',
|
|
new Enum(AppUserRolesEnum::class)
|
|
],
|
|
'status' => 'required|boolean'
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'lastname' => \trans('nom'),
|
|
'firstname' => \trans('prénom'),
|
|
'email' => \trans('email'),
|
|
'password' => \trans('mot de passe'),
|
|
'authorizedFolders' => \trans('dossiers autorisés'),
|
|
'role' => \trans('rôle'),
|
|
'status' => \trans('statut')
|
|
];
|
|
}
|
|
}
|