Pagination problem Hello all!
I'm trying to use pagination and it's works fine.
But when i add orderBy something is going wrong...
Some results partly occurs again when i click on next page...
So how can i add orderBy and remove this problem?
@Sinnbeck Lol sorry forget to post code : )
$selectedCategory = Course::where('course_category_id', $category->id)->StatusOn()->orderBy('created_at', 'desc')->paginate(18);
and on blade
{!! $selectedCategory->links() !!}
@spAo What is scopeStatusOn() ?
Other than that it should work. Any chance that the $category->id changes between you changing pages?
@Sinnbeck
public function scopeStatusOn($query)
{
return $query->where('status', '1')->whereNotNull('created_at');
}
It was
->orderBy('id')
problem i added it and now it's working : ) thanks for response
@spAo Good to know. Yeah didnt think about that. Guess my timestamps have never been that close :p
Your query is producing non-deterministic results; add id as a last order field to break ties in created_at sorting:
$selectedCategory = Course::where('course_category_id', $category->id)->StatusOn()->orderBy('created_at', 'desc')->orderBy('id')->paginate(18);
@tykus Thanks for help now it's working perfect : )
Please sign in or create an account to participate in this conversation.