<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 查询中使用分页

        时间:2023-09-24
        <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 查询中使用分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 PHP 进行 XML 分页 下一篇:没有 SQL 的 PHP 动态分页

                  相关文章

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

                    1. <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>