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

    <legend id='TKPDc'><style id='TKPDc'><dir id='TKPDc'><q id='TKPDc'></q></dir></style></legend>

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

        Laravel 5.2 - 左加入 DB::Raw 不起作用?

        时间:2023-09-22
          <bdo id='qBW8Y'></bdo><ul id='qBW8Y'></ul>
          • <small id='qBW8Y'></small><noframes id='qBW8Y'>

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

              <legend id='qBW8Y'><style id='qBW8Y'><dir id='qBW8Y'><q id='qBW8Y'></q></dir></style></legend>
                    <tbody id='qBW8Y'></tbody>
                  <tfoot id='qBW8Y'></tfoot>
                  本文介绍了Laravel 5.2 - 左加入 DB::Raw 不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有以下查询,我尝试使用 DB::Raw() 进行左连接,但出现错误:

                  I have the following query where I'm trying to use DB::Raw() for the left join but I'm getting error:

                  IlluminateDatabaseQueryBuilder::leftJoin() 缺少参数 2

                  Missing argument 2 for IlluminateDatabaseQueryBuilder::leftJoin()

                  这是我的查询:

                  return $this->model->from('alerts as a')
                      ->leftJoin(DB::Raw("locations as l on l.id = JSON_UNQUOTE(JSON_EXTRACT(a.criteria, '$.locationId'))"))
                      ->leftJoin(DB::Raw("industries as i on find_in_set(i.id, JSON_UNQUOTE(JSON_EXTRACT(a.criteria, '$.industries')))"))
                      ->where('user_id', '=', $userId)
                      ->selectRaw("a.id
                          , a.name
                          , a.criteria
                          , GROUP_CONCAT(DISTINCT(i.name) SEPARATOR ', ') as 'Industries'
                              ->groupBy('a.id')
                              ->orderBy('a.created_at', 'desc');
                  

                  推荐答案

                  leftJoin 函数声明如下:

                   public function leftJoin($table, $first, $operator = null, $second = null)
                  

                  您想将原始函数作为第二列传入:

                  You want to pass your raw functions in as the second column:

                  return $this->model->from('alerts as a')
                                     ->leftJoin('locations AS l', 'l.id', '=', DB::Raw("JSON_UNQUOTE(JSON_EXTRACT(a.criteria, '$.locationId'))"))
                                     ->leftJoin('industries as i', function($join){
                                          $join->on(DB::raw("find_in_set(i.id, JSON_UNQUOTE(JSON_EXTRACT(a.criteria,  '$.industries')))",DB::raw(''),DB::raw(''))); 
                                     })
                  
                                     ->where('user_id', '=', $userId)
                                     ->selectRaw("a.id
                                               , a.name
                                               , a.criteria
                                               , GROUP_CONCAT(DISTINCT(i.name) SEPARATOR ', ') as 'Industries'")
                                     ->groupBy('a.id')
                                     ->orderBy('a.created_at', 'desc');
                  

                  find_in_set 建议来自这里.

                  The find_in_set suggestion came from here.

                  我不确定 '$.locationId' 是什么,但如果它是一个变量,你可以将它作为一个数组中的参数作为 DB 上的第二个参数传递::raw() 函数.

                  I'm not sure what '$.locationId' is, but if it's a variable, you can pass that along as a parameter within an array as the second parameter on the DB::raw() function.

                  这篇关于Laravel 5.2 - 左加入 DB::Raw 不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 Eloquent ORM/laravel 准备好的语句 下一篇:Laravel 块和删除

                  相关文章

                  最新文章

                  <legend id='EMwP4'><style id='EMwP4'><dir id='EMwP4'><q id='EMwP4'></q></dir></style></legend>
                  <tfoot id='EMwP4'></tfoot>

                      <bdo id='EMwP4'></bdo><ul id='EMwP4'></ul>

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

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