1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace App\Repositories\Presenters;
- use League\Fractal\Pagination\IlluminatePaginatorAdapter;
- use League\Fractal\Resource\Collection;
- use League\Fractal\Resource\Item;
- use Prettus\Repository\Presenter\FractalPresenter;
- /**
- * Class CoursePresenter.
- *
- * @package namespace App\Repositories\Presenters;
- */
- abstract class BasePresenter extends FractalPresenter
- {
- protected function transformItem($data)
- {
- return new Item($data, $this->getTransformer('item'), $this->resourceKeyItem);
- }
- /**
- * Transformer
- *
- * @return \League\Fractal\TransformerAbstract
- */
- public abstract function getTransformer($type = 'list');
- protected function transformCollection($data)
- {
- return new Collection($data, $this->getTransformer('list'), $this->resourceKeyCollection);
- }
- protected function transformPaginator($paginator)
- {
- $collection = $paginator->getCollection();
- $resource = new Collection($collection, $this->getTransformer('list'), $this->resourceKeyCollection);
- $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
- return $resource;
- }
- }
|