我有一个这样的表。
user_company
user_id
company_id
user_dispensary
user_id
dispensary_id
user_group
user_id
group_id
// User.php
public function groups()
{
return $this->belongsToMany(Group::class,'user_group','user_id');
}
public function dispensary()
{
return $this->belongsToMany(Dispensary::class, 'user_dispensary', 'user_id');
}
public function company()
{
return $this->belongsToMany(Company::class, 'user_company', 'user_id');
}
// Company.php
public function dispensary()
{
return $this->hasMany(Dispensary::class);
}
public function users()
{
return $this->belongsToMany(User::class, 'user_company', 'company_id');
}
// Dispensary.php
public function company()
{
return $this->belongsTo(Company::class);
}
public function users()
{
return $this->belongsToMany(User::class, 'user_dispensary', 'dispensary_id');
}
我已经尝试过让用户所在公司的用户。
\Auth::user()->company()->first()->users
但是我要获取的是当前登录用户所在公司的所有用户及其组以及这些药房所属的药房用户的记录。
>