jeudi 29 octobre 2015

Many to many relation for a user to regions and roles

In my application there was a many to many relation between a user and regions, and the same for user and roles. Previously a user had many regions under one city. Also, a user had many roles in one city, primarily Admin as the second role.

Now there's a change in the system. A user can have two roles in multiple city.

For example: User A has 4 regions. 2 regions belong to city X and 2 belong to city Y. And user has two different roles in city X and city Y.

My current schema is below:

User
belongsToMany('App\Region', 'user_region', 'user_id', 'region_id');
belongsToMany('App\Role', 'user_role', 'user_id', 'role_id');

How can I implement this new system with my existing schema? v1 is already on production. I need to change this in v2.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire