2023-10-06 15:00:42 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Bo\Users;
|
|
|
|
|
|
|
|
|
|
use App\Enums\Users\RoleEnum;
|
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
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 auth('backend')->check();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepare the data for validation.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2025-07-24 11:32:12 +02:00
|
|
|
protected function prepareForValidation(): void
|
2023-10-06 15:00:42 +02:00
|
|
|
{
|
|
|
|
|
$this->merge([
|
2025-08-05 12:32:21 +02:00
|
|
|
'published' => $this->input('published') ? true : false,
|
|
|
|
|
'brand_id' => $this->input('brand_id') ?: [],
|
2023-10-06 15:00:42 +02:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function rules(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
2025-08-05 12:32:21 +02:00
|
|
|
'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',
|
|
|
|
|
'brand_id' => 'present|array',
|
|
|
|
|
'brand_id.*' => 'sometimes|nullable|array',
|
|
|
|
|
'brand_id.*.id' => 'sometimes|nullable|numeric|exists:brands,id',
|
2023-10-06 15:00:42 +02:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get custom attributes for validator errors.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function attributes(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
2025-08-05 12:32:21 +02:00
|
|
|
'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'),
|
|
|
|
|
'brand_id' => trans('models.classes.brands'),
|
|
|
|
|
'brand_id.*' => trans('models.classes.brands'),
|
|
|
|
|
'brand_id.*.id' => trans('models.classes.brands'),
|
2023-10-06 15:00:42 +02:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|