1. <i id='IdcAw'><tr id='IdcAw'><dt id='IdcAw'><q id='IdcAw'><span id='IdcAw'><b id='IdcAw'><form id='IdcAw'><ins id='IdcAw'></ins><ul id='IdcAw'></ul><sub id='IdcAw'></sub></form><legend id='IdcAw'></legend><bdo id='IdcAw'><pre id='IdcAw'><center id='IdcAw'></center></pre></bdo></b><th id='IdcAw'></th></span></q></dt></tr></i><div id='IdcAw'><tfoot id='IdcAw'></tfoot><dl id='IdcAw'><fieldset id='IdcAw'></fieldset></dl></div>

      <bdo id='IdcAw'></bdo><ul id='IdcAw'></ul>
  2. <legend id='IdcAw'><style id='IdcAw'><dir id='IdcAw'><q id='IdcAw'></q></dir></style></legend>

    <small id='IdcAw'></small><noframes id='IdcAw'>

      <tfoot id='IdcAw'></tfoot>

      Laravel whereIn whereJsonContains 的实现

      时间:2023-09-22

        • <small id='UkCoq'></small><noframes id='UkCoq'>

              <tbody id='UkCoq'></tbody>
            <tfoot id='UkCoq'></tfoot>

            <legend id='UkCoq'><style id='UkCoq'><dir id='UkCoq'><q id='UkCoq'></q></dir></style></legend>
              <bdo id='UkCoq'></bdo><ul id='UkCoq'></ul>

                <i id='UkCoq'><tr id='UkCoq'><dt id='UkCoq'><q id='UkCoq'><span id='UkCoq'><b id='UkCoq'><form id='UkCoq'><ins id='UkCoq'></ins><ul id='UkCoq'></ul><sub id='UkCoq'></sub></form><legend id='UkCoq'></legend><bdo id='UkCoq'><pre id='UkCoq'><center id='UkCoq'></center></pre></bdo></b><th id='UkCoq'></th></span></q></dt></tr></i><div id='UkCoq'><tfoot id='UkCoq'></tfoot><dl id='UkCoq'><fieldset id='UkCoq'></fieldset></dl></div>
                本文介绍了Laravel whereIn whereJsonContains 的实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我有这段代码可以正常工作并返回 1 个项目集合:

                I have this code that works fine and returns 1 item collection:

                $myCollection = MyModel::whereJsonContains('payload->ProductCode->id', "1")->get();
                

                但是,我不仅要在值为 1 时获取 $myCollection,而且要在它包含在多个数组项之一中时获取它.

                I however want to fetch the $myCollection not just when the value is 1 but when it is contained in one of many array items.

                 $array = [0 => 1, 1 => 2, 2 => 3];
                 $myCollection = MyModel::whereJsonContains('payload->ProductCode->id', $array)->get();
                 
                

                更新当我尝试此代码时,它返回一个空数据.我的意思是当我使用 1 而不是 1" 时.这可能是我使用数组时它不起作用的原因吗?

                UPDATES When I try this code it return an empty data. I mean when I use 1 instead of "1". Could that be the reason why it doesn't work when I use an array?

                $myCollection = MyModel::whereJsonContains('payload->ProductCode->id', 1)->get();

                有效载荷包含的示例如下.我想这可以让我的问题更清晰:

                A sample of what the payload contains is this. I suppose that could give more clarity to my question:

                {
                    "ProductCode": {
                        "id": "1",
                        "name": "My Service",
                    }
                    
                }

                运行上面的代码返回一个空数据.请问我该如何解决?

                Running the above code returns an empty data. How do I fix this please?

                推荐答案

                您需要按照以下方式查询.

                You need to follow your query as below.

                $array = [0 => 1, 1 => 2, 2 => 3];
                
                // Eloquent
                PaymentTransaction::whereJsonContains('payload->ProductCode->id',$array)->get();;
                
                 // or
                PaymentTransaction::jsonContains('payload->ProductCode->id', $array)->get();
                

                你也可以试试下面的方法.

                you can try it as below too.

                $array = [0 => 1, 1 => 2, 2 => 3];
                $array = array_values(array_map('strval',$array));
                PaymentTransaction::where(function ($query) use ($array) {
                   foreach ($array as $id) {
                       $query->orWhereJsonContains('payload->ProductCode->id', $id);
                   }
                })->get();
                

                这篇关于Laravel whereIn whereJsonContains 的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:无法 json_encode() 数组或 Laravel 集合:“不支持类型 下一篇:Laravel - 方法 Illuminate\Support\Collection::makeHidden 不

                相关文章

                最新文章

                  <legend id='c1Lqr'><style id='c1Lqr'><dir id='c1Lqr'><q id='c1Lqr'></q></dir></style></legend>
                  <i id='c1Lqr'><tr id='c1Lqr'><dt id='c1Lqr'><q id='c1Lqr'><span id='c1Lqr'><b id='c1Lqr'><form id='c1Lqr'><ins id='c1Lqr'></ins><ul id='c1Lqr'></ul><sub id='c1Lqr'></sub></form><legend id='c1Lqr'></legend><bdo id='c1Lqr'><pre id='c1Lqr'><center id='c1Lqr'></center></pre></bdo></b><th id='c1Lqr'></th></span></q></dt></tr></i><div id='c1Lqr'><tfoot id='c1Lqr'></tfoot><dl id='c1Lqr'><fieldset id='c1Lqr'></fieldset></dl></div>
                    • <bdo id='c1Lqr'></bdo><ul id='c1Lqr'></ul>
                    <tfoot id='c1Lqr'></tfoot>

                    <small id='c1Lqr'></small><noframes id='c1Lqr'>