How to select all products from a specific category if they contain sub-categories?

Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
In online store there is a table of categories(categories),
sub-categories(subcategories) with a field category_id,
and table products with a field subcategory_id.
Each subset necessarily belongs to one category. Each product in the same category.

Get all products of a particular Subcategory, you can:
$products = Product::where('subcategory_id','=', $subcategory_id)->get();

Subcategories from a specific category:
$subcategories = Subcategory::where('category_id','=', $category_id)->get();

Question - how to select all products from a specific category? The project training.
by | 20 views

1 Answer

0 like 0 dislike

Of course before that you need the relationship to prescribe some between models.

Related questions

0 like 0 dislike
1 answer
asked Apr 9, 2019 by doniyorbekm
0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
110,608 questions
257,187 answers
40,796 users