Member::where('status', 'A')->orderBy('code', 'desc')->paginate(15).
I am using ->paginate(15) with using ->orderBy('code', 'desc').
But the result in not correct. Some of the record is missing and some of the records is duplicate.
The same happens with latest()->paginate(5)
Order spoofs end results from the pagination.
https://github.com/jenssegers/laravel-mongodb/issues/437 still an issue
Paginate with orderBy having same issue.
Missing some records and some are duplicated.
use Illuminate\Pagination\Paginator;
use Illuminate\Pagination\LengthAwarePaginator;
//......
$perPage = 15;
$currentPage = $request->input('page', 1);
$offset = ($currentPage - 1) * $perPage;
$total = Member::where('status','A')->count();
$result = Member::where('status','A')->orderBy('code','desc')->offset($offset)->limit($perPage)->get();
$members = new LengthAwarePaginator($result,$total,$perPage,$currentPage,[
'path' => Paginator::resolveCurrentPath(),
'pageName' => 'page']);
@puzc1993 thanks!
@puzc1993,
How we will render this pagination in view files. Can you give example code for this.
@msankar1991
https://laravel.com/docs/5.4/pagination#displaying-pagination-results
@puzc1993 Thanks!
@puzc1993 thank you so much
$members = new LengthAwarePaginator($result,$total,$perPage,$currentPage,[
'path' => Paginator::resolveCurrentPath(),
'pageName' => 'page']);
You are saved my life 馃憣
Most helpful comment
use Illuminate\Pagination\Paginator;
use Illuminate\Pagination\LengthAwarePaginator;
//......
$perPage = 15;
$currentPage = $request->input('page', 1);
$offset = ($currentPage - 1) * $perPage;
$total = Member::where('status','A')->count();
$result = Member::where('status','A')->orderBy('code','desc')->offset($offset)->limit($perPage)->get();
$members = new LengthAwarePaginator($result,$total,$perPage,$currentPage,[
'path' => Paginator::resolveCurrentPath(),
'pageName' => 'page']);