我有2个表格:Calendar
和User
。 Calendar
有一对多的关系User
和User
具有通过parentID
与自身的关系:Laravel 5雄辩多重关系
//model Calendar.php
public function users()
{
return $this->belongsTo(User::class,'userID');
}
//model User.php
public function parent()
{
return $this->belongsTo(self::class,'parentID','id');
}
我已经选择它就像我想,但我想补充:
where('users.parent.parentID',$userID)->orWhere('users.parent.parentID',$userID);
但我不”我认为它会起作用。我试图加入,但我不知道如何。我已经试过:
$calendar = calendar::with('users','users.parent')->get()->where('users.parent.parentID',$userID);
和
$calendar = calendar::with('users','users.parent')->get()->where('users.parentID',$userID);
get()在模型查询中排在最后。 – Gokigooooks