最佳答案
追踪源码可知在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
方法对数据进行操作,然后再重新转换回来分页对象.
讨论数量:
追踪源码可知在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
方法对数据进行操作,然后再重新转换回来分页对象.
推荐文章: