request->input('page', 1); $perPage = (int) $this->request->input('per_page', 2); // 这里根据 $currentPage 和 $perPage 进行数据查询,以下使用 Collection 代替 $collection = new Collection([ ['id' => 1, 'name' => 'Tom'], ['id' => 2, 'name' => 'Sam'], ['id' => 3, 'name' => 'Tim'], ['id' => 4, 'name' => 'Joe'], ]); $users = array_values($collection->forPage($currentPage, $perPage)->toArray()); return new Paginator($users, $perPage, $currentPage); } /** * RPC调用示例 * * @return array */ public function user_info() { return $this->getServiceResult($this->userService->getUserInfo()); } }