Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. class A1 // Может быть A2 A3 etc
  2. {
  3.     public function b(): BelongsToMany
  4.     {
  5.         return $this->belongsToMany(B::class, 'entity_bs', 'entity_id', 'b_id')
  6.             ->where('entity_type', EntityType::A)
  7.             ->withPivot('*')
  8.             ->withTimestamps();
  9.     }
  10. }
  11.  
  12. class B
  13. {
  14.     public function roles(): BelongsToMany
  15.     {
  16.         return $this->belongsToMany(Role::class, 'b_roles', 'b_id', 'role_id')
  17.             ->withPivot('*')
  18.             ->withTimestamps();
  19.     }
  20. }
  21.  
  22. class Role
  23. {
  24.   // code
  25. }
  26.  
  27. pivot table (entity_bs)
  28. id entity_type(A1, A2 etc) entity_id b_id
  29. pivot table (b_roles)
  30. id entity_type(A1, A2 etc) entity_id b_id role_id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement