本文整理汇总了PHP中Illuminate\Pagination\LengthAwarePaginator::getCollection方法的典型用法代码示例。如果您正苦于以下问题:PHP LengthAwarePaginator::getCollection方法的具体用法?PHP LengthAwarePaginator::getCollection怎么用?PHP LengthAwarePaginator::getCollection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Pagination\LengthAwarePaginator
的用法示例。
在下文中一共展示了LengthAwarePaginator::getCollection方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createPagedCollection
protected function createPagedCollection(LengthAwarePaginator $paginator, TransformerAbstract $transformer)
{
$data = $paginator->getCollection();
$collection = new Collection($data, $transformer);
$collection->setPaginator(new IlluminatePaginatorAdapter($paginator));
return $this->fractal->createData($collection)->toArray();
}
示例2: respondWithPaginator
/**
* @param Paginator $data
* @param TransformerAbstract $transformer
* @param array $headers
* @return \Illuminate\Http\JsonResponse
*/
public function respondWithPaginator(LengthAwarePaginator $data, TransformerAbstract $transformer, $headers = [])
{
$manager = new Manager();
$manager->setSerializer(new ArraySerializer());
$resource = new Collection($data->getCollection(), $transformer);
$resource->setPaginator(new IlluminatePaginatorAdapter($data));
$response = $manager->createData($resource)->toArray();
return $this->respond(['post' => $this->_request->all(), 'data' => $response['data'], 'meta' => $response['meta'], 'error' => ['global' => '']], $headers);
}
示例3: getData
/**
* Get data .
*
* @param null $perPage
* @return array
*/
public function getData($perPage = null)
{
$source = $this->getSource();
$items = $source['rows'];
$offSet = @$_GET['page'] * $perPage - $perPage;
$itemsForCurrentPage = array_slice($items, $offSet, $perPage, true);
$paginator = new LengthAwarePaginator($itemsForCurrentPage, count($source['rows']), $perPage);
return ['columns' => $this->source['columns'], 'rows' => $paginator->getCollection(), 'total' => $paginator->total()];
}
示例4: __construct
/**
* Constructor.
* @param Collection|LengthAwarePaginator $collection
* @param string $class - optional
*/
public function __construct($collection, $class = null)
{
if ($collection instanceof LengthAwarePaginator) {
$this->paginator = $collection;
$this->items = $collection->getCollection();
} else {
$this->items = $collection;
}
if ($class) {
$this->setClass($class);
}
}
示例5: transformPaginated
public function transformPaginated(LengthAwarePaginator $paginator)
{
$collection = $paginator->getCollection();
try {
$transformer = TransformerFactory::makeForCollection($collection);
$resource = new Collection($collection, $transformer);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return $this->manager->createData($resource)->toArray();
} catch (\OutOfRangeException $e) {
$emptyResource = new Collection([], []);
$emptyResource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return $this->manager->createData($emptyResource)->toArray();
}
}
示例6: transformPaginator
/**
* @param AbstractPaginator|LengthAwarePaginator|Paginator $paginator
* @return \League\Fractal\Resource\Collection
*/
protected function transformPaginator($paginator)
{
$collection = $paginator->getCollection();
$resource = new Collection($collection, $this->getTransformer(), $this->resourceKeyCollection);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return $resource;
}
示例7: formateHatoeasPaged
/**
* @param LengthAwarePaginator $paged
*
* @return PaginatedRepresentation
*/
public function formateHatoeasPaged(LengthAwarePaginator $paged)
{
$request = \App::make('request');
$params = array_merge($request->route()[2], $request->all());
return new PaginatedRepresentation(new CollectionRepresentation($paged->getCollection(), null, $request->path()), $request->route()[1]['as'], $params, $paged->currentPage(), $paged->perPage(), $paged->lastPage(), 'page', 'per_page', true, $paged->total());
}
示例8: wrapPager
public static function wrapPager(LengthAwarePaginator $pager)
{
$collection = static::wrapCollection($pager->getCollection());
return new LengthAwarePaginator($collection, $pager->total(), $pager->perPage(), $pager->currentPage());
}
示例9: handlePagination
/**
* @param LengthAwarePaginator $pagination
* @param null|Fractal\TransformerAbstract $transformer
* @return array
*/
private function handlePagination(LengthAwarePaginator $pagination, $transformer = null)
{
$transformer = $transformer ?: TransformerFactory::create(class_basename($pagination->getCollection()->first()));
$resource = new Fractal\Resource\Collection($pagination->getCollection(), $transformer);
$resource->setPaginator(new Fractal\Pagination\IlluminatePaginatorAdapter($pagination));
return $this->handleResource($resource);
}