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

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 | 6 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,186 answers
33,868 users