MultiWhere.php 1.0 KB

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