Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class A1 // Может быть A2 A3 etc
- {
- public function b(): BelongsToMany
- {
- return $this->belongsToMany(B::class, 'entity_bs', 'entity_id', 'b_id')
- ->where('entity_type', EntityType::A)
- ->withPivot('*')
- ->withTimestamps();
- }
- }
- class B
- {
- public function roles(): BelongsToMany
- {
- return $this->belongsToMany(Role::class, 'b_roles', 'b_id', 'role_id')
- ->withPivot('*')
- ->withTimestamps();
- }
- }
- class Role
- {
- // code
- }
- pivot table (entity_bs)
- id entity_type(A1, A2 etc) entity_id b_id
- pivot table (b_roles)
- id entity_type(A1, A2 etc) entity_id b_id role_id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement