1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace App\Repositories\Criteria\Base;
- use Illuminate\Http\Request;
- use Prettus\Repository\Contracts\CriteriaInterface;
- use Prettus\Repository\Contracts\RepositoryInterface;
- class AreaCriteria 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('code')) {
- $model = $model->where('code', 'like', '%' . $this->request->get('code') . '%');
- }
- if ($this->request->filled('parent_id')) {
- $model = $model->where('parent_id', '=', $this->request->get('parent_id'));
- }
- return $model;
- }
- }
|