StudentCriteria.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Repositories\Criteria\Mentor;
  3. use Illuminate\Http\Request;
  4. use Prettus\Repository\Contracts\CriteriaInterface;
  5. use Prettus\Repository\Contracts\RepositoryInterface;
  6. class StudentCriteria 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('account')) {
  28. $model = $model->where('account', 'like', '%' . $this->request->get('account'));
  29. }
  30. if ($this->request->filled('mobile')) {
  31. $model = $model->where('mobile', 'like', '%' . $this->request->get('mobile'));
  32. }
  33. if ($this->request->filled('grade_id')) {
  34. $grade_id = $this->request->get('grade_id');
  35. if($grade_id){
  36. $model = $model->where('grade_id', '=', $this->request->get('grade_id'));
  37. }
  38. }
  39. if ($this->request->filled('status')) {
  40. $model = $model->where('status', '=', $this->request->get('status'));
  41. }
  42. if (!$this->request->filled('orderBy')) {
  43. $model = $model->orderByDesc('id');
  44. }
  45. return $model;
  46. }
  47. }