mercredi 20 février 2019

Laravel - Relations - A manager can have multiple shops

I'm getting crazy with a simple relation problem. I have 3 tables:

Manager:

| id  | name  |
|-----|-------|
|  1  | John  |
|  2  | Mary  |

Shops:

| id  | name    |
|-----|---------|
|  1  | Shop 1  |
|  2  | Shop 2  |

Manager_Shop

| manager_id  | shop_id | other_fk |
|-------------|---------|----------|
|      1      |    1    |    ..    |

Basically each Manager can have multiple shops but a Shop is managed by only one Manager.
I do not have the manager_id on shops table because we designed it for a future update where a shop can have also multiple managers.

Which relation should I use? Maybe a hasManyThrough? In this case the documentation is not very clear about how to use it, it require a id in the "pivot" table, ID that I don't have.

Any suggestion?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire