参客:林明潭blog](http://blog.umaske.com/article/138)
定义目录
- 在
appServices
中定义ApplySerializePaginate.php
<?php
namespace AppServices;
use IlluminatePaginationLengthAwarePaginator;
class ApplySerializePaginate extends LengthAwarePaginator
{
public function toArray()
{
return [
'data' => $this->items->toArray(),
'total' => $this->total(),
'pageSize'=>(int)$this->perPage(),
'page'=>$this->currentPage(),
];
}
}
- 在
appProviders
文件下的AppServiceProvider.php
中的register
方法中定义
use AppServicesApplySerializePaginate;
public function register()
{
//
$this->app->bind('IlluminatePaginationLengthAwarePaginator',function ($app,$options){
return new ApplySerializePaginate($options['items'], $options['total'], $options['perPage'], $options['currentPage'] , $options['options']);
});
}
格式化输出的结果示例