1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace App\Repositories\Criteria\Dwbs;
- use Illuminate\Http\Request;
- use Prettus\Repository\Contracts\CriteriaInterface;
- use Prettus\Repository\Contracts\RepositoryInterface;
- class GoodCriteria 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)
- {
- if ($this->request->filled('name')) {
- $val = $this->request->get('name');
- $model = $model->where('name', 'like', "%{$val}%");
- }
- if ($this->request->filled('status')) {
- $status = $this->request->get('status');
- $model = $model->where('status', '=', $status);
- }
- if ($this->request->filled('ids')) {
- $ids = $this->request->get('ids');
- $model = $model->whereIn('id', $ids);
- }
- if (!$this->request->filled('orderBy')) {
- $model = $model->orderByDesc('id');
- }
- return $model;
- }
- }
|