阅读(3553) (0)

Laravel 8 通过中间表过滤关系

2021-07-07 11:41:20 更新

在定义关系时,你还可以使用 wherePivotwherePivotIn 方法来过滤 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]);