45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Staff\Requests;
|
|
|
|
use App\Domains\Authorization\Enums\RoleCode;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class StoreStaffRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
protected function prepareForValidation(): void
|
|
{
|
|
if (is_string($this->input('email'))) {
|
|
$this->merge(['email' => mb_strtolower(trim($this->input('email')))]);
|
|
}
|
|
}
|
|
|
|
/** @return array<string, mixed> */
|
|
public function rules(): array
|
|
{
|
|
$categoryRules = $this->user()->tenant()->firstOrFail()
|
|
->requiresScannerCategoryValidation()
|
|
? ['required', 'array', 'min:1']
|
|
: ['sometimes', 'array'];
|
|
|
|
return [
|
|
'nombre_apellido' => ['required', 'string', 'max:255'],
|
|
'dni' => ['required', 'string', 'max:50'],
|
|
'email' => [
|
|
'required',
|
|
'email',
|
|
'max:255',
|
|
Rule::unique('users', 'active_email')->where('rol_codigo', RoleCode::Scanner->value)->whereNull('deleted_at'),
|
|
],
|
|
'category_ids' => $categoryRules,
|
|
'category_ids.*' => ['integer', 'distinct', Rule::exists('categorias', 'id')],
|
|
];
|
|
}
|
|
}
|