| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- /**
- * 代理分页查询.
- *
- * @author nj
- * @date 2021-01-23 15:35:04
- */
- namespace App\Repositories\Criterias;
- use Illuminate\Database\Eloquent\Builder;
- use KZ2\Laravel\Repositories\Contracts\RepositoryInterface;
- use KZ2\Laravel\Repositories\Criteria\Criteria;
- class AnnouncePagesCriteria extends Criteria
- {
- private $params = [];
- public function __construct($params = [])
- {
- $this->params = $params;
- }
- /**
- * @param Builder $model
- * @param RepositoryInterface $repository
- * @return mixed|void
- */
- public function apply(
- $model,
- RepositoryInterface $repository
- ) {
- if (!empty($this->params['uid'])) {
- $model = $model->where('uid', $this->params['uid']);
- }
- if (isset($this->params['type'])) {
- $type = intval($this->params['type']);
- $model = $model->where('type', $type);
- }
- if (isset($this->params['status'])) {
- $status = intval($this->params['status']);
- $model = $model->where('status', $status);
- }
- if (isset($this->params['title'])) {
- $title = trim($this->params['title']);
- $model = $model->where('title', 'LIKE' , '%'.$title.'%');
- }
- return $model;
- }
- }
|