久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在laravel 5.2中使用分頁()的distinct()不起作用

distinct() with pagination() in laravel 5.2 not working(在laravel 5.2中使用分頁()的distinct()不起作用)
本文介紹了在laravel 5.2中使用分頁()的distinct()不起作用的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在嘗試在 laravel 5.2 中使用 distinct()pagination() 流利,結(jié)果正確,但分頁仍然存在相同(就像沒有應(yīng)用不同).

I'm trying to use distinct() with pagination() in laravel 5.2 with fluent and it's given result proper but pagination remain same(Like without apply distinct).

我已經(jīng)使用我的代碼查看并測試了以下答案
- laravel 5 - 使用不同的分頁對 total() 查詢/a>
- 分頁 &與眾不同
- 使用 distinct 時(shí)查詢生成器分頁方法計(jì)數(shù)錯(cuò)誤

我的代碼類似于:

DB::table('myTable1 AS T1')
->select('T1.*')
->join('myTable2 AS T2','T2.T1_id','=','T1.id')
->distinct()
->paginate(5);

示例
- 我得到了三個(gè)記錄(即 POST1、POST2、POST3POST1)的結(jié)果,所以我應(yīng)用了 distinct().
- 現(xiàn)在我的結(jié)果是 POST1、POST2POST3 但分頁仍然顯示為 4 條記錄(作為應(yīng)用 distinct() 之前的結(jié)果).

EXAMPLE
- I have result with three records(i.e. POST1, POST2, POST3 and POST1) so I apply distinct().
- Now my result is POST1, POST2 and POST3 but pagination still display like 4 records(As result before applied distinct()).

任何建議將不勝感激!

推薦答案

Laravel 和在分頁中使用 distinct 似乎存在一些持續(xù)的問題.

There seems to be some ongoing issues with Laravel and using distinct with pagination.

在這種情況下,當(dāng)分頁確定記錄總數(shù)時(shí),它會(huì)忽略您在 select() 子句中指定的字段.由于它忽略了您的列,因此也忽略了不同的功能.因此,計(jì)數(shù)查詢變?yōu)?select count(*) as aggregate from ...

In this case, when pagination is determining the total number of records, it is ignoring the fields you have specified in your select() clause. Since it ignores your columns, the distinct functionality is ignored as well. So, the count query becomes select count(*) as aggregate from ...

要解決此問題,您需要將您的列的分頁功能告知.傳遞您的列數(shù)組以選擇作為第二個(gè)參數(shù),它會(huì)將它們計(jì)入總計(jì)數(shù).所以,如果你這樣做:

To resolve the issue, you need to tell the paginate function about your columns. Pass your array of columns to select as the second parameter, and it will take them into account for the total count. So, if you do:

/*DB::stuff*/->paginate(5, ['T1.*']);

這將運(yùn)行計(jì)數(shù)查詢:

select count(distinct T1.*) as aggregate from

因此,您的查詢應(yīng)如下所示:

So, your query should look like:

DB::table('myTable1 AS T1')
    ->select('T1.*')
    ->join('myTable2 AS T2','T2.T1_id','=','T1.id')
    ->distinct()
    ->paginate(5, ['T1.*']);

這篇關(guān)于在laravel 5.2中使用分頁()的distinct()不起作用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Magento products by categories(按類別劃分的 Magento 產(chǎn)品)
Resource interpreted as image but transferred with MIME type text/html - Magento(資源被解釋為圖像但使用 MIME 類型 text/html 傳輸 - Magento)
Is there an event for customer account registration in Magento?(Magento 中是否有客戶帳戶注冊事件?)
Magento addFieldToFilter: Two fields, match as OR, not AND(Magento addFieldToFilter:兩個(gè)字段,匹配為 OR,而不是 AND)
quot;Error 404 Not Foundquot; in Magento Admin Login Page(“未找到錯(cuò)誤 404在 Magento 管理員登錄頁面)
Get Order Increment Id in Magento(在 Magento 中獲取訂單增量 ID)
主站蜘蛛池模板: 国产一区二区久久久 | 婷婷精品| 成年人视频免费在线观看 | 久久中文字幕视频 | 99国内精品久久久久久久 | 成人在线观看亚洲 | 国产精品国产精品国产专区不蜜 | 91精品久久久久久久 | 一区二区三区在线 | 免费观看一区二区三区毛片 | 精品国产乱码久久久久久丨区2区 | 国产www. | 日韩色综合 | 亚洲欧洲日韩精品 中文字幕 | 一级毛片,一级毛片 | 欧美性大战久久久久久久蜜臀 | 五月天国产视频 | 一区二区三区免费在线观看 | 成人性视频免费网站 | 三级黄色片在线 | 亚洲第一视频网站 | 日本视频免费 | 在线观看毛片网站 | 久久国产精品99久久久久久丝袜 | 国产精品免费看 | 中文字幕 亚洲一区 | 国产一区二区三区四区区 | 在线视频亚洲 | 午夜寂寞影院列表 | 精品免费国产 | 男人天堂久久久 | 午夜国产羞羞视频免费网站 | 亚洲国产免费 | 国产亚洲精品久久久久动 | www久久| 久久综合一区二区三区 | 亚洲高清电影 | 成年人免费看 | 欧美一区二区免费 | 丁香综合 | av三级|