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

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

                  相关文档推荐

                  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 的问题)

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