Reputation: 131
Is there a way Laravel can tell you which page a record is on? So you can set the browser view to that page?
Upvotes: 0
Views: 128
Reputation: 40909
In general, in order to determine on which page a record would be displayed you'd need first to load all the records as pagination.
It's a bit easier with sorted result lists. You could try to do that using some SQL. You'd need to count number of records that come before the record you need and then calculate the number of page that would contain your record, e.g.:
//You want to find out on which page a record with ID = 35 will be shown:
$perPage = 10;
// Count number of record where ID is smaller than 35
$count = YourModel::where('id', '<', 35)->count();
// Calculate page number for your record
$pageNumber = floor($count / $perPage) + 1;
Upvotes: 1