check(); } public function rules(): array { $roleId = (int) ( $this->route('roleId') ?? $this->route('id') ?? $this->input('id') ?? 0 ); $current = $roleId > 0 ? Role::query()->find($roleId) : null; $currentName = strtolower(trim((string) ($current?->name ?? ''))); $currentSlug = strtolower(trim((string) ($current?->slug ?? ''))); $nameInput = $this->input('name', ''); $slugInput = $this->input('slug', ''); $incomingName = is_scalar($nameInput) ? strtolower(trim((string) $nameInput)) : ''; $incomingSlug = is_scalar($slugInput) ? strtolower(trim((string) $slugInput)) : ''; $nameRules = ['sometimes', 'string', 'min:3', 'max:255']; if ($incomingName !== '' && $incomingName !== $currentName) { $nameRules[] = Rule::unique('roles', 'name')->ignore($roleId); } $slugRules = ['nullable', 'string', 'max:64']; if ($incomingSlug !== '' && $incomingSlug !== $currentSlug) { $slugRules[] = Rule::unique('roles', 'slug')->ignore($roleId); } return [ 'name' => $nameRules, 'slug' => $slugRules, 'description' => ['nullable', 'string', 'max:500'], 'dashboard_route' => ['sometimes', 'string', 'min:1', 'max:255', 'regex:/^[a-z0-9_\\/\\-]+$/'], 'priority' => ['sometimes', 'integer', 'min:0', 'max:100000'], 'is_active' => ['sometimes', Rule::in([0, 1, '0', '1', true, false])], ]; } }