ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
添加以下方法就可以 ~~~ public function paginationInformation($request, $paginated, $default): array { return [ 'page' => [ 'page' => $paginated['current_page'], 'per_page' => $paginated['per_page'], 'total' => $paginated['total'], 'total_page' => $paginated['last_page'], ] ]; } ~~~ 变成以下状态 ~~~ <?php namespace App\Http\Resources; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\ResourceCollection; class UserCollection extends ResourceCollection { use BaseResource; public static $wrap = 'list'; /** * Transform the resource collection into an array. * * @return array<int|string, mixed> */ public function toArray(Request $request): array { return [ 'list' => $this->collection, ]; } public function paginationInformation($request, $paginated, $default): array { return [ 'page' => [ 'page' => $paginated['current_page'], 'per_page' => $paginated['per_page'], 'total' => $paginated['total'], 'total_page' => $paginated['last_page'], ] ]; } } ~~~ 写父类里面也可以 ~~~ trait BaseResource { public function paginationInformation($request, $paginated, $default): array { return [ 'page' => [ 'page' => $paginated['current_page'], 'per_page' => $paginated['per_page'], 'total' => $paginated['total'], 'total_page' => $paginated['last_page'], ] ]; } } ~~~