Laravel 5分页-滚动到包含特定记录的页面


Laravel 5 pagination - scrolling to a page containing a specfic record

是否有一种方法Laravel可以告诉您记录在哪个页面上?所以你可以将浏览器视图设置为那个页面?

一般来说,为了确定记录将显示在哪个页面上,您需要首先加载所有记录作为分页。

使用排序结果列表会更容易一些。您可以尝试使用一些SQL来做到这一点。你需要计算在你需要的记录之前的记录的数量,然后计算包含你的记录的页数,例如:

//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;