我有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