LogCriteria.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Repositories\Criteria\Base;
  3. use Illuminate\Http\Request;
  4. use Prettus\Repository\Contracts\CriteriaInterface;
  5. use Prettus\Repository\Contracts\RepositoryInterface;
  6. class LogCriteria implements CriteriaInterface
  7. {
  8. /**
  9. * @var \Illuminate\Http\Request
  10. */
  11. protected $request;
  12. public function __construct(Request $request)
  13. {
  14. $this->request = $request;
  15. }
  16. /**
  17. * @param $model
  18. * @param RepositoryInterface $repository
  19. *
  20. * @return mixed
  21. */
  22. public function apply($model, RepositoryInterface $repository)
  23. {
  24. // this is a Example
  25. //if ($this->request->filled('name')) {
  26. // $model = $model->where('name', '=', $this->request->get('name'));
  27. //}
  28. if ($this->request->filled('url')) {
  29. $model = $model->where('url', 'like', $this->request->get('url') . '%');
  30. }
  31. if ($this->request->filled('method')) {
  32. $model = $model->where('method', '=', $this->request->get('method'));
  33. }
  34. if ($this->request->filled('username')) {
  35. $model = $model->where('username', 'like', $this->request->get('username') . '%');
  36. }
  37. if ($this->request->filled('start_date')) {
  38. $model = $model->whereDate('created_at', '>=', $this->request->get('start_date'));
  39. }
  40. if ($this->request->filled('end_date')) {
  41. $model = $model->whereDate('created_at', '<', $this->request->get('end_date'));
  42. }
  43. return $model;
  44. }
  45. }