Laravel 8 通过中间表过滤关系
2021-07-19 11:34 更新
在定义关系时,你还可以使用 wherePivot 和 wherePivotIn 方法来过滤 belongsToMany 返回的结果:
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]); 以上内容是否对您有帮助:

免费 AI IDE


更多建议: