我有一個名為unit具有這種關系的模型/** * Get the users associated with the unit */public function users(){ return $this->hasMany('App\Models\User\UserData');}在UserData模型中有一列user_id,我試圖將其放入查詢中。我正在嘗試執行這樣的查詢Unit::where('user_id', Auth::id())->first()user_id但表中沒有列Unit,只有users關系
1 回答

三國紛爭
TA貢獻1804條經驗 獲得超7個贊
最終做了這個
Unit::whereHas('users', function($q) { $q->where('user_id', Auth::id()); })->first();
- 1 回答
- 0 關注
- 101 瀏覽
添加回答
舉報
0/150
提交
取消