Answer the question
In order to leave comments, you need to log in
What is the correct way to get relations through relation 1->3 eloquent?
I have three entities. Many-to-many relationships.
Keyword
Recipe
Category
Relationships between lower entities in tables in the database.
category_keyword
keyword_recipe
To make the category_recipe link I did the following
$category = Category::with(['keywords'])->where('code', $code)->first();
$recipes = collect();
foreach ($category->keywords as $keyword){
foreach ($keyword->recipes as $recipe){
$recipes->push($recipe);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question