JobCriteria.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Repositories\Criteria\Base;
  3. use App\Repositories\Enums\Base\AdminTypeEnum;
  4. use Illuminate\Http\Request;
  5. use Prettus\Repository\Contracts\CriteriaInterface;
  6. use Prettus\Repository\Contracts\RepositoryInterface;
  7. class JobCriteria implements CriteriaInterface
  8. {
  9. /**
  10. * @var \Illuminate\Http\Request
  11. */
  12. protected $request;
  13. public function __construct(Request $request)
  14. {
  15. $this->request = $request;
  16. }
  17. /**
  18. * @param $model
  19. * @param RepositoryInterface $repository
  20. *
  21. * @return mixed
  22. */
  23. public function apply($model, RepositoryInterface $repository)
  24. {
  25. // this is a Example
  26. //if ($this->request->filled('name')) {
  27. // $model = $model->where('name', '=', $this->request->get('name'));
  28. //}
  29. if ($this->request->filled('name')) {
  30. $model = $model->where('name', 'like', '%' . $this->request->get('name') . '%');
  31. }
  32. if ($this->request->filled('code')) {
  33. $model = $model->where('code', 'like', '%' . $this->request->get('code') . '%');
  34. }
  35. if ($this->request->filled('status')) {
  36. $model = $model->where('status', '=', $this->request->get('status'));
  37. }
  38. // $admin = login_admin();
  39. // switch ($admin['type']) {
  40. // case AdminTypeEnum::ADMIN:
  41. // $company_id = $admin['company_id'];
  42. // if ($company_id) $model = $model->where('company_id', '=', $company_id);
  43. // break;
  44. // }
  45. // $model = $model->orderByDesc('sort')->orderByDesc('id');
  46. return $model;
  47. }
  48. }