Here is my code:
$upcoming_collections = Collection::upcoming()->with( 'watchlists','blockchain')->where('status', 'published');
if($blockChain){
$upcoming_collections = $upcoming_collections->whereRelation('blockchain', 'slug',$blockChain);
}
$upcoming_collections = $upcoming_collections->orderBy('release_date','asc')->orderBy('last_day_vote_count', 'desc')->simplePaginate($count);
This is showing many duplicate records on some other pages. And upcoming is a local scope defined as:
public function scopeUpcoming($query): \Illuminate\Database\Eloquent\Builder
{
return $query->where('release_date', '>=', now())->orWhere('release_date', null)->orWhere('to_be_announced', 1);
}
Here, the release date is a nullable DateTime field, and last_day_vote_count is the integer column. This is repeating items on clicking next page, on multiple pages.
But, if I try without ordering, something is as follows. It works fine.
$upcoming_collections = $upcoming_collections->simplePaginate($count);