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

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

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

        Laravel - 同时联合 + 分页?

        Laravel - Union + Paginate at the same time?(Laravel - 同时联合 + 分页?)
            <tbody id='EPSE6'></tbody>
          • <small id='EPSE6'></small><noframes id='EPSE6'>

              <legend id='EPSE6'><style id='EPSE6'><dir id='EPSE6'><q id='EPSE6'></q></dir></style></legend>
              <tfoot id='EPSE6'></tfoot>
                <i id='EPSE6'><tr id='EPSE6'><dt id='EPSE6'><q id='EPSE6'><span id='EPSE6'><b id='EPSE6'><form id='EPSE6'><ins id='EPSE6'></ins><ul id='EPSE6'></ul><sub id='EPSE6'></sub></form><legend id='EPSE6'></legend><bdo id='EPSE6'><pre id='EPSE6'><center id='EPSE6'></center></pre></bdo></b><th id='EPSE6'></th></span></q></dt></tr></i><div id='EPSE6'><tfoot id='EPSE6'></tfoot><dl id='EPSE6'><fieldset id='EPSE6'></fieldset></dl></div>
                  <bdo id='EPSE6'></bdo><ul id='EPSE6'></ul>
                • 本文介绍了Laravel - 同时联合 + 分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  简介:

                  我正在尝试合并 2 个表 recipesposts,然后将 ->paginate(5) 添加到查询中.

                  I am trying to union 2 tables recipes and posts then add ->paginate(5) to the queries.

                  但由于某种原因,我收到此错误:

                  But for some reason I get this error:

                  基数违规:1222 使用的 SELECT 语句有一个不同的列数(SQL:(选择计数(*)作为聚合来自帖子

                  Cardinality violation: 1222 The used SELECT statements have a different number of columns (SQL: (select count(*) as aggregate from posts

                  代码:

                  $recipes = DB::table("recipes")->select("id", "title", "user_id", "description", "created_at")
                                      ->where("user_id", "=", $id);
                  
                  $items = DB::table("posts")->select("id", "title", "user_id", "content", "created_at")
                                  ->where("user_id", "=", $id)
                                  ->union($recipes)
                                  ->paginate(5)->get();
                  

                  我做错了吗?

                  没有 ->paginate(5) 查询工作正常.

                  Without ->paginate(5) the query works fine.

                  推荐答案

                  你说得对,分页导致问题.现在,您可以创建一个视图并查询该视图而不是实际的表,手动创建您的 Paginator:

                  You're right, pagination cause problem. Right now, you can create a view and query the view instead of the actual tables, or create your Paginator manually:

                  $page = Input::get('page', 1);
                  $paginate = 5;
                  
                  $recipes = DB::table("recipes")->select("id", "title", "user_id", "description", "created_at")
                              ->where("user_id", "=", $id);
                  $items = DB::table("posts")->select("id", "title", "user_id", "content", "created_at")
                              ->where("user_id", "=", $id)
                              ->union($recipes)
                              ->get();
                  
                  $slice = array_slice($items->toArray(), $paginate * ($page - 1), $paginate);
                  $result = Paginator::make($slice, count($items), $paginate);
                  
                  return View::make('yourView',compact('result'));
                  

                  这篇关于Laravel - 同时联合 + 分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                        <tfoot id='9hfR8'></tfoot>
                          <tbody id='9hfR8'></tbody>
                        • <legend id='9hfR8'><style id='9hfR8'><dir id='9hfR8'><q id='9hfR8'></q></dir></style></legend>

                          <small id='9hfR8'></small><noframes id='9hfR8'>

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