123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace App\Repositories\Criteria;
- use App\Repositories\Enums\ModelStatusEnum;
- use Illuminate\Http\Request;
- use Prettus\Repository\Contracts\CriteriaInterface;
- use Prettus\Repository\Contracts\RepositoryInterface;
- class BannerCriteria extends RequestCriteria implements CriteriaInterface
- {
- /**
- * @var \Illuminate\Http\Request
- */
- protected $request;
- public function __construct(Request $request)
- {
- $this->request = $request;
- }
- /**
- * @inheritDoc
- */
- public function apply($model, RepositoryInterface $repository)
- {
- if ($name = $this->request->get('name', false)) {
- $model = $model->where('name', 'like', "%{$name}%");
- }
- if ($this->request->filled('shop_id')) {
- $shop_id = $this->request->get('shop_id');
- $model = $model->where('shop_ids', 'like', "-{$shop_id}-");
- }
- if ($this->request->filled('type')) {
- $type = $this->request->get('type');
- $model = $model->where('type', $type);
- }
- if ($status = $this->request->get('status', ModelStatusEnum::OK)) {
- $model = $model->where('status', $status);
- }
- // $model = $model->orderByDesc("id");
- return parent::apply($model, $repository);
- }
- }
|