BannerCriteria.php 961 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Repositories\Criteria\Base;
  3. use Illuminate\Http\Request;
  4. use Prettus\Repository\Contracts\CriteriaInterface;
  5. use Prettus\Repository\Contracts\RepositoryInterface;
  6. class BannerCriteria implements CriteriaInterface
  7. {
  8. /**
  9. * @var \Illuminate\Http\Request
  10. */
  11. protected $request;
  12. public function __construct(Request $request)
  13. {
  14. $this->request = $request;
  15. }
  16. /**
  17. * @param $model
  18. * @param RepositoryInterface $repository
  19. *
  20. * @return mixed
  21. */
  22. public function apply($model, RepositoryInterface $repository)
  23. {
  24. // this is a Example
  25. //if ($this->request->filled('name')) {
  26. // $model = $model->where('name', '=', $this->request->get('name'));
  27. //}
  28. if ($this->request->filled('type')) {
  29. $type = $this->request->get('type');
  30. $model = $model->where('type', '=', $type);
  31. }
  32. return $model;
  33. }
  34. }