1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Repositories\Criteria\Base;
- use Illuminate\Http\Request;
- use Prettus\Repository\Contracts\CriteriaInterface;
- use Prettus\Repository\Contracts\RepositoryInterface;
- class TaskCriteria 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')) {
- $model = $model->where('name', 'like', '%' . $this->request->get('name') . '%');
- }
- if ($this->request->filled('type')) {
- $model = $model->where('type', 'like', '%' . $this->request->get('type') . '%');
- }
- if ($this->request->filled('type_id')) {
- $model = $model->where('type_id', '=', $this->request->get('type_id'));
- }
- if ($this->request->filled('admin_id')) {
- $model = $model->where('admin_id', '=', $this->request->get('admin_id'));
- }
- if ($this->request->filled('make_status')) {
- $model = $model->where('make_status', '=', $this->request->get('make_status'));
- }
- $model = $model->orderByDesc('id');
- return $model;
- }
- }
|