BasePresenter.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Repositories\Presenters;
  3. use League\Fractal\Pagination\IlluminatePaginatorAdapter;
  4. use League\Fractal\Resource\Collection;
  5. use League\Fractal\Resource\Item;
  6. use Prettus\Repository\Presenter\FractalPresenter;
  7. /**
  8. * Class CoursePresenter.
  9. *
  10. * @package namespace App\Repositories\Presenters;
  11. */
  12. abstract class BasePresenter extends FractalPresenter
  13. {
  14. protected function transformItem($data)
  15. {
  16. return new Item($data, $this->getTransformer('item'), $this->resourceKeyItem);
  17. }
  18. /**
  19. * Transformer
  20. *
  21. * @return \League\Fractal\TransformerAbstract
  22. */
  23. public abstract function getTransformer($type = 'list');
  24. protected function transformCollection($data)
  25. {
  26. return new Collection($data, $this->getTransformer('list'), $this->resourceKeyCollection);
  27. }
  28. protected function transformPaginator($paginator)
  29. {
  30. $collection = $paginator->getCollection();
  31. $resource = new Collection($collection, $this->getTransformer('list'), $this->resourceKeyCollection);
  32. $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
  33. return $resource;
  34. }
  35. }