Multiple many to many relationships across multiple pivot tables #188
-
Hello, I'm struggling with the relationships in my tables. Looking at the structure in the image below (exclude the single_pivot_table, I scrapped that idea). A menu item can be on multiple menus, a menu can be on multiple periods, and menus can exist across multiple locations. All of this is defined and working with data, but my problem is calling a relationship across different relationships. Example, I can do The only way to do this today is to call Any thoughts? Can this package solve this use case or am I completely crazy with this structure. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @idealerror, class Item extends Model
{
use \Staudenmeir\EloquentHasManyDeep\HasRelationships;
public function locations()
{
return $this->hasManyDeep(
Location::class,
['menu_items', Menu::class, 'period_menus', Period::class, 'location_periods']
);
}
} |
Beta Was this translation helpful? Give feedback.
Hi @idealerror,
Define the relationship like this: