66 lines
1.7 KiB
PHP
66 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\Users;
|
|
|
|
use App\Enums\Users\RoleEnum;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Validation\Rules\Enum;
|
|
|
|
class StoreUserRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return Gate::check('create', User::class);
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'published' => $this->boolean('published')
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 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',
|
|
'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'),
|
|
'role' => trans('validation.attributes.role'),
|
|
'published' => trans('validation.custom.publication')
|
|
];
|
|
}
|
|
}
|