workspace_id) ? (int) $tenant->workspace_id : null; if ($workspaceId === null) { throw new InvalidArgumentException('Tenant-scoped audit events require tenant workspace_id.'); } return AuditLog::create([ 'tenant_id' => $tenant->id, 'workspace_id' => $workspaceId, 'actor_id' => $actorId, 'actor_email' => $actorEmail, 'actor_name' => $actorName, 'action' => $action, 'resource_type' => $resourceType, 'resource_id' => $resourceId, 'status' => $status, 'metadata' => $sanitizedMetadata, 'recorded_at' => CarbonImmutable::now(), ]); } }