Hello, tell me, is it normal when there are so many requests to the database? Is it possible to pack in one request? Screenshot requests Connection many to many.

public function tags() { return $this->belongsToMany('App\Tag', 'recipe_tags'); } @foreach($recipes as $recipe) @foreach ($recipe->tags as $tag){{$tag->name }} //запросы идут из-за получения тегов рецепта. @endforeach @endforeach 

    1 answer 1

    Use eager loading to get $ recipes

     $recipes = Recipe::with('tags')->...->get(); 

    or

     $recipes = Recipe::...->get()->load('tags'); 
    • Thanks, that's exactly what I did that evening. - axblue