2023-11-23 17:31:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-02 12:09:46 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2023-11-23 17:31:28 +01:00
|
|
|
namespace App\Http\Requests\Bo\Users;
|
|
|
|
|
|
|
|
|
|
use App\Enums\Users\RoleEnum;
|
2024-01-31 09:03:18 +00:00
|
|
|
use App\Models\User;
|
2023-11-23 17:31:28 +01:00
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
2023-12-05 12:33:25 +01:00
|
|
|
use Illuminate\Support\Facades\Gate;
|
2023-11-23 17:31:28 +01: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.
|
|
|
|
|
*
|
2026-10-02 12:09:46 +02:00
|
|
|
* @return bool
|
2023-11-23 17:31:28 +01:00
|
|
|
*/
|
2023-12-05 12:33:25 +01:00
|
|
|
public function authorize()
|
2023-11-23 17:31:28 +01:00
|
|
|
{
|
2023-12-05 12:33:25 +01:00
|
|
|
return Gate::check('create', User::class);
|
2023-11-23 17:31:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepare the data for validation.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected function prepareForValidation()
|
|
|
|
|
{
|
|
|
|
|
$this->merge([
|
2026-10-02 12:09:46 +02:00
|
|
|
'published' => $this->boolean('published'),
|
2023-11-23 17:31:28 +01:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
|
*/
|
|
|
|
|
public function rules(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'first_name' => 'required|string|min:3|max:255',
|
2026-10-02 12:09:46 +02:00
|
|
|
'last_name' => 'required|string|min:3|max:255',
|
|
|
|
|
'email' => 'required|email:rfc,strict,dns,spoof,filter|unique:users,email',
|
|
|
|
|
'password' => [
|
2023-11-23 17:31:28 +01:00
|
|
|
'required', 'required_with:password_confirmation', 'confirmed', 'max:255', Password::min(8)
|
|
|
|
|
->letters()
|
|
|
|
|
->mixedCase()
|
|
|
|
|
->numbers()
|
|
|
|
|
->symbols()
|
2026-10-02 12:09:46 +02:00
|
|
|
->uncompromised(),
|
2023-11-23 17:31:28 +01:00
|
|
|
],
|
2026-10-02 12:09:46 +02:00
|
|
|
'role' => ['required', new Enum(RoleEnum::class)],
|
2023-11-23 17:31:28 +01:00
|
|
|
'published' => 'required|boolean',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get custom attributes for validator errors.
|
|
|
|
|
*/
|
|
|
|
|
public function attributes(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'first_name' => trans('validation.attributes.first_name'),
|
2026-10-02 12:09:46 +02:00
|
|
|
'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'),
|
2023-11-23 17:31:28 +01:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|