ldc-com-app-bo/app/Http/Requests/Bo/AppUser/StoreAppUserRequest.php
2023-03-31 16:53:04 +02:00

72 lines
1.9 KiB
PHP

<?php
namespace App\Http\Requests\Bo\AppUser;
use App\Enums\AppUserRolesEnum;
use Illuminate\Foundation\Http\FormRequest;
use Kwaadpepper\Enum\Rules\EnumIsValidRule;
class StoreAppUserRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize()
{
return auth('backend')->check();
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation()
{
$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()
{
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|nullable|required_with:password_confirmation|confirmed|min:8|max:255',
'authorizedFolders' => 'present|array',
'role' => [
'required',
new EnumIsValidRule(AppUserRolesEnum::class)
],
'status' => 'required|boolean'
];
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes()
{
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')
];
}
}