This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I have a project with a Recipe, Recipetype, Menu.
Recipe Model:
protected $guarded = ['*'];
protected $fillable = [];
public $belongsTo = [
'recipetype' => Recipetype::class
];
Recipetype Model:
/*
* Relationships
*/
public $hasMany = [
'recipes' => Opskrift::class
];
public $belongsToMany = [
'menues' => [
Menu::class,
'table' => 'kitchen_recipes_recipetype_menues',
'key' => 'recipetype_id',
'otherKey' => 'menu_id'
]
];
Menu Model
/*
* Relationships
*/
public $hasMany = [
'recipetypes' => Recipetype::class
];
The idea is, that a Recipe can be, let's say Tomato Soup. The soup belongs to a Recipetype, which could be Starter. A Menu can then hold some Recipetypes.
What I have is a page where you press a menu, say menu A. I'm then looking for a query to take the selected menu (A menu has id 1), find the Recipetypes associated with menu A in the pivot table (let's say Recipe types with id 2 and 5), and THEN find the recipes. I'm not quite sure how to achieve this with the nested relations I have. Or is there a better way to build this?
Last updated
1-1 of 1