-
app/App/Admin/ViewModels/AdminAnalyticsViewModel.php
Open in GitHubuse Domain\Source\Models\Source; use Illuminate\Support\Collection; use Spatie\ViewModels\ViewModel; final class AdminAnalyticsViewModel extends ViewModel { // public function topSources(): Collection { $sources = Source::query() ->selectRaw('sources.*, SUM(posts.view_count) AS view_count, SUM(posts.vote_count) AS vote_count') ->joinPosts() ->groupBy('sources.url') ->applySort($this->request) ->limit(10) ->get(); return $sources; } // }