MultiWhere.php 906 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * User: Mike
  4. * Email: m@9026.com
  5. * Date: 2017/1/12
  6. * Time: 17:52
  7. */
  8. namespace App\Repositories\Order\Criteria;
  9. use App\Repositories\Base\Criteria;
  10. use App\Repositories\Contracts\RepositoryInterface as Repository;
  11. class MultiWhere extends Criteria
  12. {
  13. private $search = [];
  14. /**
  15. * MultiWhere constructor.
  16. * @param array $search
  17. *
  18. */
  19. public function __construct(array $search)
  20. {
  21. $this->search = $search;
  22. }
  23. /**
  24. * @param $model
  25. * @param RepositoryInterface $repository
  26. * @return mixed
  27. */
  28. public function apply($model, Repository $repository)
  29. {
  30. if (isset($this->search['keyword']) && $this->search['keyword']) {
  31. $model = $model->where('order_no', 'like', $this->search['keyword'])
  32. ->orwhere('code', 'like', $this->search['keyword']);
  33. }
  34. return $model;
  35. }
  36. }