Laravel 8 通過中間表過濾關(guān)系

2021-07-19 11:34 更新

在定義關(guān)系時(shí),你還可以使用 wherePivotwherePivotIn 方法來過濾 belongsToMany 返回的結(jié)果:

return $this->belongsToMany('App\Models\Role')->wherePivot('approved', 1);

return $this->belongsToMany('App\Models\Role')->wherePivotIn('priority', [1, 2]);

return $this->belongsToMany('App\Models\Role')->wherePivotNotIn('priority', [1, 2]); 
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)