Answer the question
In order to leave comments, you need to log in
Find pagination page by order ID, error?
Good evening, I have a page with pagination, 50 posts per page. In total, there are more than 2k records. In some situations, I need to know on which page, which record is located. In general, I thought that nothing complicated and wrote the following code:
$id = request()->onote;
$per_page = 50;
$total_page = $this->has('removals')
->wherehas('removals.product')
->where('archived', 0)
->paginate($per_page)
->lastPage();
$index = $this->has('removals')
->wherehas('removals.product')
->where('archived', 0)
->where('id', '<=', $id)
->count();
$page = round($index/$per_page);
$page = ($total_page-$page);
Answer the question
In order to leave comments, you need to log in
I really didn’t want to, but I had to do everything with the help of recursion, since the problem needed to be solved as quickly as possible.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question