Lecturer::query() ->whereHas('libraryItems', function ($query) { $query->where('library_items.news', true); }) ->withCount([ 'libraryItems' => fn($query) => $query->where('library_items.news', true), ]) ->orderByDesc('library_items_count') ->get(), ])->layout('layouts.app', [ 'SEOData' => new SEOData( title: __('News articles writer'), description: __('Click on any of the authors to see their articles.'), image: asset('img/einundzwanzig-news-colored.png'), ), ]); } }