loading = true; $topLinks = Link::where('workspace_id', $workspace->id) ->withCount('clicks') ->orderByDesc('clicks_count') ->limit(10) ->get(['slug', 'target_url', 'clicks_count']); $summary = $topLinks->map(fn ($l) => "{$l->slug}: {$l->clicks_count} clicks → {$l->target_url}")->implode("\n"); $prompt = "You are a marketing analyst. Analyze these link performance stats and provide 3-5 actionable insights:\n\n{$summary}\n\nBe concise and specific."; $this->insights = app(AiService::class)->complete($prompt); $this->loading = false; } public function render(): View { return view('livewire.pages.ai.insights') ->layout('layouts.nimuli-app', ['title' => 'AI Insights']); } }