我需要在laravel分页中设置当前页面,而无需从get参数获取页面号。
诸如此类的东西:
$fetch = Post::paginate()->setCurrentPage(3);
有可能吗?
是,可以覆盖Paginator::currentPageResolver()来更改确定页面的方式:
Paginator::currentPageResolver(fn() => 10);
$users = User::paginate(); // you now will be on page 10
不幸的是,由于该属性受到保护并且没有吸气剂,因此无法重置或检索PaginationServiceProvider中设置的原始功能。