Laravel查询生成器:不在其中的枢轴 [英] Laravel Query Builder : Where pivot not in
问题描述
wherePivotIn
在此处(在通过中间表列过滤关系),但是我找不到任何与之相反的功能.
wherePivotIn
is mentionend here (under Filtering Relationships Via Intermediate Table Columns) but I can't find anything about the opposite function.
由于wherePivotIn
已经存在,但wherePivotNOTIn
不存在,所以我编辑了该文件:vendor/laravel/framework/src/Illuminate/Database/Eloquant/Relations/BelongsToMany.php
As the wherePivotIn
already exists but not the wherePivotNOTIn
, I edited this file : 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
存在并且正在工作.但是我的问题是:
Now the wherePivotNotIn
exist and is working. But my question is:
更新此文件安全吗? 如果有更新,我想我会丢失的...
Is it safe to update this file? In case of update, I guess I will lose this...
推荐答案
稍作讨论后,我发现whereIn
方法接受两个以上的参数.
After dinging a bit, I found out that the whereIn
method accept more than 2 arguments.
我们不得不像这样使用它来使用"wherePivot 不输入"
We juste have to use it like that to use a "wherePivotNotIn"
->wherePivotIn($column,$value,'and','NotIn')
无需声明新类或使用范围!
No need to declare a new class or using scope!
这篇关于Laravel查询生成器:不在其中的枢轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!