Advertisement
wansyahi1

query

Dec 26th, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. public function filterQuery(Request $request){
  2.  
  3. $age = $request->age;
  4. $age2 = $request->age2;
  5. $dataGender = $request->dataGender;
  6. $ethnicity = $request->ethnicity;
  7. $area = $request->area;
  8. $state = $request->state;
  9. $namaDUN = $request->namaDUN;
  10. $income = $request->income;
  11. $income = $request->income;
  12. $education = $request->education;
  13. $digitalInclination = $request->digitalInclination;
  14. $employment = $request->employment;
  15. $carOwnership = $request->carOwnership;
  16. $carOwnership2 = $request->carOwnership2;
  17.  
  18. //join table by IC as PK
  19. $query = ModifiedDppr::query();
  20. $query->join('modified_dpprs2018_algorithm', 'modified_dpprs2018_algorithm.IC', '=', 'modified_dpprs.IC')
  21. ->select('id', 'First_name', 'Last_name', 'Umur', 'Phonenum', 'TarikhLahir','Negeri', 'Country', 'postcode', 'Ct', 'Jantina');
  22.  
  23. //from table = modified_dpprs
  24. if(!empty($request->age)){
  25. $query->where('modified_dpprs.modified_dpprs.Umur','>=',$age);
  26. }
  27.  
  28. if(!empty($request->age2)){
  29. $query->where('modified_dpprs.modified_dpprs.Umur','<=',$age2);
  30. }
  31.  
  32. if(!empty($request->dataGender)){
  33. $query->whereIn('modified_dpprs.Jantina',$dataGender); //multiselect whereIn
  34. }
  35.  
  36. if(!empty($request->ethnicity)){
  37. $query->whereIn('modified_dpprs.Bangsa_updated',$ethnicity);
  38. }
  39.  
  40. if(!empty($request->area)){
  41. $query->whereIn('modified_dpprs.Taman_area',$area);
  42. }
  43.  
  44. if(!empty($request->state)){
  45. $query->whereIn('modified_dpprs.Negeri',$state);
  46. }
  47.  
  48. if(!empty($request->namaDUN)){
  49. $query->whereIn('modified_dpprs.namaDUN',$namaDUN);
  50. }
  51.  
  52. //from table = modified_dpprs2018_algorithm
  53.  
  54. if(!empty($request->income)){
  55. $query->whereIn('modified_dpprs2018_algorithm.income_latest',$income);
  56. }
  57.  
  58. if(!empty($request->education)){
  59. $query->whereIn('modified_dpprs2018_algorithm.Education',$education);
  60. }
  61.  
  62. if(!empty($request->digitalInclination)){
  63. $query->whereIn('modified_dpprs2018_algorithm.digital_inclination',$digitalInclination);
  64. }
  65.  
  66. if(!empty($request->employment)){
  67. $query->whereIn('modified_dpprs2018_algorithm.Employment',$employment);
  68. }
  69.  
  70. if(!empty($request->carOwnership)){
  71. $query->where('modified_dpprs2018_algorithm.prob_owncar','>=',$carOwnership);
  72. }
  73.  
  74. if(!empty($request->carOwnership2)){
  75. $query->where('modified_dpprs2018_algorithm.prob_owncar','<=',$carOwnership2);
  76. }
  77.  
  78. $data = $query->select('modified_dpprs.*')->get();
  79.  
  80. return datatables()->of($data)->make(true);
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement