Eager load it?
Products::query()
->with('attributes')
->paginate(10);
I ran into this issue and can't figure out how to solve it. There are, for example, 100 products. Each product has its own attributes.
id title color size brand category
1 title1 red 30 adidas shoes
2 title2 black 30 puma shoes
3 title3 blue 28 puma shoes
To get the goods, I make the following request
$products = Product::getProducts($category, $allAttributes);
I am using pagination:
public static function getProducts ($category, $allAttributes) {
return static::select(['id', 'title', 'color'', 'size'', 'brand])
->where([
['category', $category],
])
->paginate(10);
}
As a result, I get 100 products and divide the pagination into 10 products. This works fine. But when I want to get the available attributes (color, size, brand), I get data from the current 10 products. How to get data for all products on each pagination page?
Please or to participate in this conversation.