AreaCriteria.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 AreaCriteria 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. if ($this->request->filled('name')) {
  25. $model = $model->where('name', 'like', '%' . $this->request->get('name') . '%');
  26. }
  27. if ($this->request->filled('code')) {
  28. $model = $model->where('code', 'like', '%' . $this->request->get('code') . '%');
  29. }
  30. if ($this->request->filled('parent_id')) {
  31. $model = $model->where('parent_id', '=', $this->request->get('parent_id'));
  32. }
  33. return $model;
  34. }
  35. }