B
B
Boooom2019-03-29 18:05:08
Laravel
Boooom, 2019-03-29 18:05:08

Outputting a bundle of categories with products - how to set a limit on the output?

Good evening!
I ran into this problem - when I output a bunch:

// Получаем товары для блока "Популярные товары"
$products = Category::with('goods_product')->where('siteID', $siteID)->where('type', 1)->where('published', 1)->get();

and in the model by writing limit:
public function goods_product()
{
    return $this->hasMany('App\Model\Goods', 'category', 'id')->where('published', 1)->limit(8)->with('images');
}

Then in the view it displays 8 products for each category.
How to make a restriction so that it displays 8 products in total for all categories, and not for each?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question