2023-12-19 15:09:12 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Bo\Users;
|
|
|
|
|
|
|
|
|
|
use App\Enums\Users\RoleEnum;
|
2024-01-26 16:08:12 +01:00
|
|
|
use App\Models\User;
|
2023-12-19 15:09:12 +00:00
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
2024-01-26 16:08:12 +01:00
|
|
|
use Illuminate\Support\Facades\Gate;
|
2023-12-19 15:09:12 +00:00
|
|
|
use Illuminate\Validation\Rules\Enum;
|
|
|
|
|
use Illuminate\Validation\Rules\Password;
|
|
|
|
|
|
|
|
|
|
class StoreUserRequest extends FormRequest
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
public function authorize(): bool
|
|
|
|
|
{
|
2024-01-26 16:08:12 +01:00
|
|
|
return Gate::check('create', User::class);
|
2023-12-19 15:09:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepare the data for validation.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2024-01-26 16:08:12 +01:00
|
|
|
protected function prepareForValidation(): void
|
2023-12-19 15:09:12 +00:00
|
|
|
{
|
|
|
|
|
$this->merge([
|
2024-01-26 16:08:12 +01:00
|
|
|
'published' => $this->boolean('published')
|
2023-12-19 15:09:12 +00:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function rules(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'first_name' => 'required|string|min:3|max:255',
|
|
|
|
|
'last_name' => 'required|string|min:3|max:255',
|
|
|
|
|
'email' => 'required|email:rfc,strict,dns,spoof,filter|unique:users,email',
|
|
|
|
|
'password' => [
|
|
|
|
|
'required', 'required_with:password_confirmation', 'confirmed', 'max:255', Password::min(8)
|
|
|
|
|
->letters()
|
|
|
|
|
->mixedCase()
|
|
|
|
|
->numbers()
|
|
|
|
|
->symbols()
|
|
|
|
|
->uncompromised()
|
|
|
|
|
],
|
|
|
|
|
'role' => ['required', new Enum(RoleEnum::class)],
|
|
|
|
|
'published' => 'required|boolean',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get custom attributes for validator errors.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function attributes(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'first_name' => trans('validation.attributes.first_name'),
|
|
|
|
|
'last_name' => trans('validation.attributes.last_name'),
|
|
|
|
|
'email' => trans('validation.attributes.email'),
|
|
|
|
|
'password' => trans('validation.attributes.password'),
|
|
|
|
|
'role' => trans('validation.attributes.role'),
|
|
|
|
|
'published' => trans('validation.custom.publication')
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|