讨论数量:
追踪源码可知在Illuminate/Pagination/AbstractPaginator.php中:
/**
* Get the paginator's underlying collection.
*
* @return \Illuminate\Support\Collection
*/
public function getCollection()
{
return $this->items;
}
/**
* Set the paginator's underlying collection.
*
* @param \Illuminate\Support\Collection $collection
* @return $this
*/
public function setCollection(Collection $collection)
{
$this->items = $collection;
return $this;
}
查看注释可知 getCollection 方法返回值是一个集合对象,然后集合对象就可以调用集合中的map方法对值进行操作.然后再次调用setCollection方法返回的是当前对象,也就是Illuminate\Pagination\LengthAwarePaginator这个分页对象,就是Laravel-admin需要的数据格式.
以下是我在tinker中测试的结果:


总结就是先转换成集合对象,然后调用集合的
map方法对数据进行操作,然后再重新转换回来分页对象.

关于 LearnKu
追踪源码可知在
Illuminate/Pagination/AbstractPaginator.php中:查看注释可知
getCollection方法返回值是一个集合对象,然后集合对象就可以调用集合中的map方法对值进行操作.然后再次调用setCollection方法返回的是当前对象,也就是Illuminate\Pagination\LengthAwarePaginator这个分页对象,就是Laravel-admin需要的数据格式.以下是我在



tinker中测试的结果: