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

    <small id='1253M'></small><noframes id='1253M'>

    <tfoot id='1253M'></tfoot><legend id='1253M'><style id='1253M'><dir id='1253M'><q id='1253M'></q></dir></style></legend>

        • <bdo id='1253M'></bdo><ul id='1253M'></ul>

        如何在 Laravel DB::select 查询中使用分页

        How to use pagination with laravel DB::select query(如何在 Laravel DB::select 查询中使用分页)
        <legend id='gU3nF'><style id='gU3nF'><dir id='gU3nF'><q id='gU3nF'></q></dir></style></legend>

          1. <small id='gU3nF'></small><noframes id='gU3nF'>

            <tfoot id='gU3nF'></tfoot>
              <bdo id='gU3nF'></bdo><ul id='gU3nF'></ul>
                  <tbody id='gU3nF'></tbody>

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

                  本文介绍了如何在 Laravel DB::select 查询中使用分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在 Laravel 中开展一个项目,并使用 DB Facade 运行 sql 的原始查询.就我而言,我使用的是 DB::select,问题是分页方法不适用于此 DB 原始查询并显示此错误

                  I am working on a project in Laravel and using DB facade to run raw queries of sql. In my case I am using DB::select, problem is that pagination method is not working with this DB raw query and showing this error

                  Call to a member function paginate() on array
                  

                  我只想知道如何使用 DB 原始查询实现 Laravel 分页这是我的代码:

                  I just want how to implement laravel pagination with DB raw queries here is my code:

                  <?php
                  
                  namespace AppHttpControllers;
                  
                  use IlluminateHttpRequest;
                  use AppNotice;
                  use IlluminateSupportFacadesDB;
                  use IlluminatePaginationPaginator;
                  use IlluminatePaginationLengthAwarePaginator;
                  
                  class NoticeController extends Controller
                  {
                  
                  public function index(){
                  
                      $notices = DB::select('select 
                  notices.id,notices.title,notices.body,notices.created_at,notices.updated_at,
                      users.name,departments.department_name
                      FROM notices
                      INNER JOIN users ON notices.user_id = users.id
                      INNER JOIN departments on users.dpt_id = departments.id
                      ORDER BY users.id DESC')->paginate(20);
                  
                      $result = new Paginator($notices,2,1,[]);
                  
                      return view('welcome')->with('allNotices', $notices);
                   }
                  }
                  

                  推荐答案

                  尝试:

                  $notices = DB::table('notices')
                          ->join('users', 'notices.user_id', '=', 'users.id')
                          ->join('departments', 'users.dpt_id', '=', 'departments.id')
                          ->select('notices.id', 'notices.title', 'notices.body', 'notices.created_at', 'notices.updated_at', 'users.name', 'departments.department_name')
                          ->paginate(20);
                  

                  这篇关于如何在 Laravel DB::select 查询中使用分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Appending GET parameters to URL from lt;formgt; action(将 GET 参数附加到来自 lt;formgt; 的 URL行动)
                  Forcing quot;Save Asquot; dialog via jQuery GET(强制“另存为通过 jQuery GET 对话框)
                  PHP - get certain word from string(PHP - 从字符串中获取某个单词)
                  How to debug a get request in php using curl(如何使用 curl 在 php 中调试 get 请求)
                  get a # from a url in php(从 php 中的 url 获取 #)
                  PHP - include() file not working when variables are put in url?(PHP - 将变量放入 url 时,include() 文件不起作用?)

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

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

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

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