| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace App\Repositories\Criterias;
- use KZ2\Repositories\Contracts\RepositoryInterface;
- use KZ2\Repositories\Criteria\Criteria;
- class CreatorPagesCriteria extends Criteria
- {
- private $params = [];
- public function __construct($params = [])
- {
- $this->params = $params;
- }
- public function apply(
- $model,
- RepositoryInterface $repository
- ) {
- if (!empty($this->params['id'])) {
- $model = $model->where('id', $this->params['id']);
- }
- if (!empty($this->params['status'])) {
- $model = $model->where('status', $this->params['status']);
- }
- if (isset($this->params['level']) && $this->params['level'] != '') {
- $model = $model->where('level', $this->params['level']);
- }
- if (!empty($this->params['is_bot']) && $this->params['is_bot'] != '') {
- $model = $model->where('is_bot', $this->params['is_bot']);
- }
- if (!empty($this->params['user_nick'])) {
- $model = $model->whereHas('user', function($q) {
- $q->where('nick', $this->params['user_nick']);
- });
- }
- if (!empty($this->params['user_code'])) {
- $model = $model->whereHas('user', function($q) {
- $q->where('code', $this->params['user_code']);
- });
- }
- if (!empty($this->params['user_mobile'])) {
- $model = $model->whereHas('user', function($q) {
- $q->where('mobile', $this->params['user_mobile']);
- });
- }
- return $model;
- }
- }
|