'Laravel simplePaginate not working correctly, its repeating many data on every different page
My code:
$query = Collection::with( 'watchlists','blockchain')
->where('status', 'published')
->where(function($q){
$q->where('release_date', '>=', now())
->orWhere('release_date', null)
->orWhere('to_be_announced', 1);
});
if(!empty($blockchain_slug)){
$blockchain = Blockchain::where('slug',$blockchain_slug)->first();
$query->where('blockchain_id', $blockchain->id);
}
$records = $query->orderBy('release_date','desc')->orderBy('last_day_vote_count', 'desc')->simplePaginate(12);
On page 1 its not repeating any data, when I click view more, its repeating some data, and so on on each page.
However, if I remove ->orderBy('release_date','desc')->orderBy('last_day_vote_count', 'desc' this orderBy it works fine without repeating any data.
Basically, release_date is a datetime column and could have the null value as well. Similarly, last_day_vote_count is just an integer field.
Strange thing is that it seems working on windows xampp but not working on ubuntu (LAMP) stack.
When I click on view_more this the query seems to be running to load page2 data:
select * from `collections` where `status` = ? and (`release_date` >= ? or `release_date` is null or `to_be_announced` = ?) order by `release_date` desc, `last_day_vote_count` desc limit 13 offset 12
and bindings:
"bindings" => array:3 [
0 => "published" //status
1 => Illuminate\Support\Carbon @1652663986 {#1599 //release_date
#endOfTime: false
#startOfTime: false
#constructedObjectId: "0000000059f3b7ac00000000500ec9f4"
#localMonthsOverflow: null
#localYearsOverflow: null
#localStrictModeEnabled: null
#localHumanDiffOptions: null
#localToStringFormat: null
#localSerializer: null
#localMacros: null
#localGenericMacros: null
#localFormatFunction: null
#localTranslator: null
#dumpProperties: array:3 [
0 => "date"
1 => "timezone_type"
2 => "timezone"
]
#dumpLocale: null
#dumpDateProperties: null
date: 2022-05-16 01:19:46.331307 UTC (+00:00)
}
2 => 1 //to_be_announced
What could be the issue here and how could I debug?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
