123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace App\Repositories\Criteria\Base;
- use Illuminate\Http\Request;
- use Prettus\Repository\Contracts\CriteriaInterface;
- use Prettus\Repository\Contracts\RepositoryInterface;
- class DictCriteria implements CriteriaInterface
- {
- /**
- * @var \Illuminate\Http\Request
- */
- protected $request;
- public function __construct(Request $request)
- {
- $this->request = $request;
- }
- /**
- * @param $model
- * @param RepositoryInterface $repository
- *
- * @return mixed
- */
- public function apply($model, RepositoryInterface $repository)
- {
- // this is a Example
- //if ($this->request->filled('name')) {
- // $model = $model->where('name', '=', $this->request->get('name'));
- //}
- if ($this->request->filled('name')) {
- $model = $model->where('name', 'like', '%' . $this->request->get('name') . '%');
- }
- if ($this->request->filled('code')) {
- $model = $model->where('code', 'like', '%' . $this->request->get('code') . '%');
- }
- if ($this->request->filled('codes')) {
- $model = $model->whereIn('code', str2arr($this->request->get('codes')));
- }
- return $model;
- }
- }
|