getKey() : $user; $cleanMetadata = array_filter($metadata, static fn (mixed $value): bool => $value !== null && $value !== ''); return AuthAuditLog::query()->create([ 'event_type' => $eventType, 'identifier' => $this->normalizeIdentifier($identifier), 'user_id' => $userId, 'ip' => $request?->ip(), 'user_agent' => $request?->userAgent(), 'status' => $status, 'reason' => $reason, 'metadata' => $cleanMetadata === [] ? null : $cleanMetadata, 'created_at' => now(), ]); } private function normalizeIdentifier(?string $identifier): ?string { $identifier = trim((string) $identifier); return $identifier === '' ? null : mb_strtolower($identifier); } }