我有一個名為
timeslot.
這個模型有一個名為的屬性(整數)
requested_participants
這個模型也有一個關系,以便附加參與者:
public function participants()
{
return $this->belongsToMany(Human::class, 'humans_timeslots', 'timeslot_id', 'human_id');
}
我想檢索較少的記錄
participants
比
requested_participants
我試過這樣的事情:
Timeslot::withCount('participants')
->having('participants_count','<','requested_resources')
->get();
但這不起作用!
如果我使用整數而不是
requested_resources
喜歡 :
Timeslot::withCount('participants')
->having('participants_count','<',2)
->get();
但不具有屬于同一模型的此屬性。有人有想法嗎?
uj5u.com熱心網友回復:
您可以使用havingRaw方法做到這一點:
Timeslot::withCount('participants')
->havingRaw('participants_count < requested_resources')
->get();
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/537378.html
標籤:拉维雄辩
