feat(users): enforce active email uniqueness per role
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Domains\Staff\Requests;
|
||||
|
||||
use App\Domains\Authorization\Enums\RoleCode;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
@@ -12,6 +13,13 @@ class StoreStaffRequest extends FormRequest
|
||||
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
|
||||
{
|
||||
@@ -27,7 +35,7 @@ class StoreStaffRequest extends FormRequest
|
||||
'required',
|
||||
'email',
|
||||
'max:255',
|
||||
Rule::unique('users', 'email')->whereNull('deleted_at'),
|
||||
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')],
|
||||
|
||||
Reference in New Issue
Block a user