Laravel查询生成器:不在其中的枢轴 [英] Laravel Query Builder : Where pivot not in

查看:53
本文介绍了Laravel查询生成器:不在其中的枢轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆