1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace App\Repositories\Criteria\Base;
- use Illuminate\Http\Request;
- use Prettus\Repository\Contracts\CriteriaInterface;
- use Prettus\Repository\Contracts\RepositoryInterface;
- class LogCriteria 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('url')) {
- $model = $model->where('url', 'like', $this->request->get('url') . '%');
- }
- if ($this->request->filled('method')) {
- $model = $model->where('method', '=', $this->request->get('method'));
- }
- if ($this->request->filled('username')) {
- $model = $model->where('username', 'like', $this->request->get('username') . '%');
- }
- if ($this->request->filled('start_date')) {
- $model = $model->whereDate('created_at', '>=', $this->request->get('start_date'));
- }
- if ($this->request->filled('end_date')) {
- $model = $model->whereDate('created_at', '<', $this->request->get('end_date'));
- }
- return $model;
- }
- }
|