MultiWhere.php 1009 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Repositories\Call\Lists\Criteria;
  3. use App\Repositories\Base\Criteria;
  4. use App\Repositories\Contracts\RepositoryInterface as Repository;
  5. class MultiWhere extends Criteria
  6. {
  7. private $search = [];
  8. /**
  9. * MultiWhere constructor.
  10. * @param array $search
  11. *
  12. */
  13. public function __construct(array $search)
  14. {
  15. $this->search = $search;
  16. }
  17. /**
  18. * @param $model
  19. * @param RepositoryInterface $repository
  20. * @return mixed
  21. */
  22. public function apply($model, Repository $repository)
  23. {
  24. if (isset($this->search['keyword']) && $this->search['keyword']) {
  25. $model = $model->where('id', 'like', '%' . $this->search['keyword'] . '%')
  26. ->orWhere('phone', 'like', '%' . $this->search['keyword'] . '%')
  27. ->orWhere('ip', 'like', '%' . $this->search['keyword'] . '%')
  28. ->orWhere('sync', 'like', '%' . $this->search['keyword'] . '%');
  29. }
  30. return $model;
  31. }
  32. }