wherePivotIn
是提及结束 here (在通过中间表列过滤关系下),但我找不到任何有关相反函数的信息。
由于 wherePivotIn
已经存在,但 wherePivotNOTIn
不存在,我编辑了此文件:vendor/laravel/framework/src/Illuminate/Database/Eloquant/Relations/BelongsToMany.php
并添加了这个功能
public function wherePivotNotIn($column, $values, $boolean = 'and', $not = false)
{
$this->pivotWhereIns[] = func_get_args();
return $this->whereNotIn($this->table.'.'.$column, $values, $boolean, $not);
}
现在 wherePivotNotIn
存在并且正在工作。但我的问题是:
更新此文件安全吗? 如果更新的话,我想我会失去这个......
最佳答案
经过一番研究,我发现 whereIn
方法接受超过 2 个参数。
我们只需像这样使用“wherePivotNotIn”
->wherePivotIn($column,$value,'and','NotIn')
无需声明新类或使用作用域!
关于sql - Laravel 查询生成器 : Where pivot not in,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48519583/