a lot of my models and other code is here and related to this question:
laravel - Query Builder vs. Eloquent
I have this query:
$recipes = Recipe::whereHas('categories', function($q) use ($cat_id) {
$q->where('category_id', $cat_id);
})->with('user')->get();
Works great if I choose (example) ID = 5. I get all recipes which have category_id = 5.
What if...
Let's say, the category_id = 5 has the parent with the id = 1 (Main categories have ID 1-3 and all children have 4 to x).
I need now, that if someone clicks the main category, in this case, ID = 1, that I can get ALL recipes that are related to the main category including the children. So I get all from Category 1 and all from 5 (and so on).
I have NO clue, how I can set the relationship or built the query.
Second is, that I also need to implement this function into the "advanced search" method of the website, but I think, if I can solve this question, the rest is "easy".
Help is appreciated. Thank you!