CreatorPagesCriteria.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Repositories\Criterias;
  3. use KZ2\Repositories\Contracts\RepositoryInterface;
  4. use KZ2\Repositories\Criteria\Criteria;
  5. class CreatorPagesCriteria extends Criteria
  6. {
  7. private $params = [];
  8. public function __construct($params = [])
  9. {
  10. $this->params = $params;
  11. }
  12. public function apply(
  13. $model,
  14. RepositoryInterface $repository
  15. ) {
  16. if (!empty($this->params['id'])) {
  17. $model = $model->where('id', $this->params['id']);
  18. }
  19. if (!empty($this->params['status'])) {
  20. $model = $model->where('status', $this->params['status']);
  21. }
  22. if (isset($this->params['level']) && $this->params['level'] != '') {
  23. $model = $model->where('level', $this->params['level']);
  24. }
  25. if (!empty($this->params['is_bot']) && $this->params['is_bot'] != '') {
  26. $model = $model->where('is_bot', $this->params['is_bot']);
  27. }
  28. if (!empty($this->params['user_nick'])) {
  29. $model = $model->whereHas('user', function($q) {
  30. $q->where('nick', $this->params['user_nick']);
  31. });
  32. }
  33. if (!empty($this->params['user_code'])) {
  34. $model = $model->whereHas('user', function($q) {
  35. $q->where('code', $this->params['user_code']);
  36. });
  37. }
  38. if (!empty($this->params['user_mobile'])) {
  39. $model = $model->whereHas('user', function($q) {
  40. $q->where('mobile', $this->params['user_mobile']);
  41. });
  42. }
  43. return $model;
  44. }
  45. }