user(); if (! $user instanceof User) { return; } WorkspaceMembership::query()->firstOrCreate( [ 'workspace_id' => $this->record->getKey(), 'user_id' => $user->getKey(), ], [ 'role' => 'owner', ], ); app(WorkspaceAuditLogger::class)->log( workspace: $this->record, action: 'workspace.created', actor: $user, resourceType: 'workspace', resourceId: (string) $this->record->getKey(), context: [ 'metadata' => [ 'workspace_id' => (int) $this->record->getKey(), 'slug' => (string) $this->record->slug, ], ], ); app(WorkspaceContext::class)->setCurrentWorkspace($this->record, $user, request()); } }