| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- /**
- * 排序条件限制规范.
- *
- * @author jim <jim458734573@gmail.com>
- * @date 2020-01-16 17:38:16
- */
- declare(strict_types=1);
- namespace App\Repositories\Criterias;
- use KZ2\Repositories\Contracts\RepositoryInterface;
- use KZ2\Repositories\Criteria\Criteria;
- class OrderLimitCriteria extends Criteria
- {
- private $order = [];
- private $limit = 0;
- public function __construct($order = [], $limit = 0)
- {
- $this->order = $order;
- $this->limit = $limit;
- }
- public function apply($model, RepositoryInterface $repository)
- {
- if (!empty($this->order)) {
- foreach ($this->order as $item) {
- $model = $model->orderBy($item[0], $item[1]);
- }
- }
- if (!empty($this->limit)) {
- $model = $model->take($this->limit);
- }
- return $model;
- }
- }
|