Awesome q2a theme

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

0 like 0 dislike
36 views
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 | 36 views

1 Answer

0 like 0 dislike
https://laravel.com/docs/5.6/eloquent-relationships
whereHas

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

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
0 comments
40,796 users