@@ -168,16 +168,13 @@ public function recipeQuality(): array
168168 /**
169169 * Get top ingredients by recipe count.
170170 *
171- * @return Collection<int, stdClass >
171+ * @return Collection<int, Ingredient >
172172 */
173173 public function topIngredients (): Collection
174174 {
175- /** @var Collection<int, stdClass> */
176- return Cache::remember ('portal_top_ingredients ' , $ this ->cacheTtl , static fn (): Collection => DB ::table ('ingredients ' )
177- ->join ('ingredient_recipe ' , 'ingredients.id ' , '= ' , 'ingredient_recipe.ingredient_id ' )
178- ->join ('countries ' , 'ingredients.country_id ' , '= ' , 'countries.id ' )
179- ->select ('ingredients.name ' , 'countries.code as country_code ' , 'countries.locales as country_locales ' , DB ::raw ('COUNT(ingredient_recipe.recipe_id) as recipes_count ' ))
180- ->groupBy ('ingredients.id ' , 'ingredients.name ' , 'countries.code ' , 'countries.locales ' )
175+ /** @var Collection<int, Ingredient> */
176+ return Cache::remember ('portal_top_ingredients ' , $ this ->cacheTtl , static fn (): Collection => Ingredient::withCount ('recipes ' )
177+ ->with ('country:id,code ' )
181178 ->orderByDesc ('recipes_count ' )
182179 ->limit (10 )
183180 ->get ());
@@ -186,16 +183,13 @@ public function topIngredients(): Collection
186183 /**
187184 * Get top tags by recipe count.
188185 *
189- * @return Collection<int, stdClass >
186+ * @return Collection<int, Tag >
190187 */
191188 public function topTags (): Collection
192189 {
193- /** @var Collection<int, stdClass> */
194- return Cache::remember ('portal_top_tags ' , $ this ->cacheTtl , static fn (): Collection => DB ::table ('tags ' )
195- ->join ('recipe_tag ' , 'tags.id ' , '= ' , 'recipe_tag.tag_id ' )
196- ->join ('countries ' , 'tags.country_id ' , '= ' , 'countries.id ' )
197- ->select ('tags.name ' , 'countries.code as country_code ' , 'countries.locales as country_locales ' , DB ::raw ('COUNT(recipe_tag.recipe_id) as recipes_count ' ))
198- ->groupBy ('tags.id ' , 'tags.name ' , 'countries.code ' , 'countries.locales ' )
190+ /** @var Collection<int, Tag> */
191+ return Cache::remember ('portal_top_tags ' , $ this ->cacheTtl , static fn (): Collection => Tag::withCount ('recipes ' )
192+ ->with ('country:id,code ' )
199193 ->orderByDesc ('recipes_count ' )
200194 ->limit (10 )
201195 ->get ());
@@ -204,16 +198,13 @@ public function topTags(): Collection
204198 /**
205199 * Get top cuisines by recipe count.
206200 *
207- * @return Collection<int, stdClass >
201+ * @return Collection<int, Cuisine >
208202 */
209203 public function topCuisines (): Collection
210204 {
211- /** @var Collection<int, stdClass> */
212- return Cache::remember ('portal_top_cuisines ' , $ this ->cacheTtl , static fn (): Collection => DB ::table ('cuisines ' )
213- ->join ('cuisine_recipe ' , 'cuisines.id ' , '= ' , 'cuisine_recipe.cuisine_id ' )
214- ->join ('countries ' , 'cuisines.country_id ' , '= ' , 'countries.id ' )
215- ->select ('cuisines.name ' , 'countries.code as country_code ' , 'countries.locales as country_locales ' , DB ::raw ('COUNT(cuisine_recipe.recipe_id) as recipes_count ' ))
216- ->groupBy ('cuisines.id ' , 'cuisines.name ' , 'countries.code ' , 'countries.locales ' )
205+ /** @var Collection<int, Cuisine> */
206+ return Cache::remember ('portal_top_cuisines ' , $ this ->cacheTtl , static fn (): Collection => Cuisine::withCount ('recipes ' )
207+ ->with ('country:id,code ' )
217208 ->orderByDesc ('recipes_count ' )
218209 ->limit (10 )
219210 ->get ());
0 commit comments