NoticeCriteria.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Repositories\Criteria\Info;
  3. use Illuminate\Http\Request;
  4. use Prettus\Repository\Contracts\CriteriaInterface;
  5. use Prettus\Repository\Contracts\RepositoryInterface;
  6. class NoticeCriteria 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. if ($this->request->filled('name')) {
  25. $model = $model->where('name', 'like', '%' . $this->request->get('name') . '%');
  26. }
  27. if ($this->request->filled('status')) {
  28. $model = $model->where('status', '=', $this->request->get('status'));
  29. }
  30. if ($this->request->filled('release_time')) {
  31. $release_time = $this->request->get('release_time');
  32. if (count($release_time) == 2) {
  33. $model = $model->where('release_time', '>=', $release_time[0])->where('release_time', '<', $release_time[1]);
  34. }
  35. }
  36. return $model;
  37. }
  38. }