具有两个whereIn的查询子句 [英] Query clause with two whereIn

查看:330
本文介绍了具有两个whereIn的查询子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试运行此查询,直到:

I try to run this query , all is good till :

-> whereIn('statut_licence_id',['1','4'])

->whereIn('statut_licence_id', ['1' , '4'])

这第二个whereIn似乎不起作用,它仅向我显示statut_licence_id = 1而不是4,现在有人如何解决该问题?

this second whereIn seems to not work , it's display me only statut_licence_id = 1 and not also 4 , someone now how to resolve the problem ?

        $licencies = Licencies::whereIn('structure_id', $structures->pluck('id'))->whereIn('type_licence_id', ['1', '2', '3', '4', '5'])
            ->whereIn('statut_licence_id', ['1' , '4'])
            ->where('valid_licence_id', '1')
            ->where('lb_assurance_etat' ,'=' , 'Assurée')
            ->orderBy('created_at', 'DESC')
            ->paginate(10);

问题通过解决:

$licencies = Licencies::whereIn('structure_id', $structures->pluck('id'))->whereIn('type_licence_id', ['1', '2', '3', '4', '5']) ->where(function ($query) {
            $query->whereIn('statut_licence_id', ['1' , '4'])
            ->where('valid_licence_id', '1'); })
            ->orderBy('created_at', 'DESC')
            ->paginate(10);

推荐答案

尝试使用闭包.

$licencies = Licencies::whereIn('structure_id', $structures->pluck('id'))->whereIn(function ($query){
             $query->whereIn('type_licence_id', ['1', '2', '3', '4', '5'])
            ->whereIn('statut_licence_id', ['1' , '4']);
        })
        ->where('valid_licence_id', '1')
        ->where('lb_assurance_etat' ,'=' , 'Assurée')
        ->orderBy('created_at', 'DESC')
        ->paginate(10);

这篇关于具有两个whereIn的查询子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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