Advertisement
wansyahi1

query

Jan 22nd, 2020
143
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.  
  4.  
  5. $age = $request->age;
  6. $age2 = $request->age2;
  7. $dataGender = $request->dataGender;
  8. $ethnicity = $request->ethnicity;
  9. $area = $request->area;
  10. $state = $request->state;
  11. $namaDUN = $request->namaDUN;
  12. $income = $request->income;
  13.  
  14. $income = $request->income;
  15. $education = $request->education;
  16. $digitalInclination = $request->digitalInclination;
  17. $employment = $request->employment;
  18. $carOwnership = $request->carOwnership;
  19. $carOwnership2 = $request->carOwnership2;
  20.  
  21.  
  22. //join table by IC as PK
  23. $query = ModifiedDppr::query();
  24. $query->join('modified_dppr2018_algorithm', 'modified_dppr2018_algorithm.IC', '=', 'modified_dppr2018.IC');
  25.  
  26.  
  27. //from table = modified_dpprs
  28. if(!empty($request->age)){
  29. $query->where('modified_dppr2018.Umur','>=',$age);
  30. }
  31.  
  32. if(!empty($request->age2)){
  33. $query->where('modified_dppr2018.Umur','<=',$age2);
  34. }
  35.  
  36. if(!empty($request->dataGender)){
  37. $query->whereIn('modified_dppr2018.Jantina',$dataGender); //multiselect whereIn
  38. }
  39.  
  40. if(!empty($request->ethnicity)){
  41. $query->whereIn('modified_dppr2018.Bangsa_updated',$ethnicity);
  42. }
  43.  
  44. if(!empty($request->area)){
  45. $query->whereIn('modified_dppr2018.Taman_area',$area);
  46. }
  47.  
  48. if(!empty($request->state)){
  49. $query->whereIn('modified_dppr2018.Negeri',$state);
  50. }
  51.  
  52. if(!empty($request->namaDUN)){
  53. $query->whereIn('modified_dppr2018.namaDUN',$namaDUN);
  54. }
  55.  
  56. if(!empty($request->income)){
  57. $query->whereIn('modified_dppr2018_algorithm.income_latest',$income);
  58. }
  59.  
  60. if(!empty($request->education)){
  61. $query->whereIn('modified_dppr2018_algorithm.Education',$education);
  62. }
  63.  
  64. if(!empty($request->digitalInclination)){
  65. $query->whereIn('modified_dppr2018_algorithm.digital_inclination',$digitalInclination);
  66. }
  67.  
  68. if(!empty($request->employment)){
  69. $query->whereIn('modified_dppr2018_algorithm.Employment',$employment);
  70. }
  71.  
  72. if(!empty($request->carOwnership)){
  73. $query->where('modified_dppr2018_algorithm.prob_owncar','>=',$carOwnership);
  74. }
  75.  
  76. $records_per_page = 100;
  77. $data = $query->select('modified_dppr2018.id','modified_dppr2018.First_name', 'modified_dppr2018.Last_name',
  78. 'modified_dppr2018.Umur', 'modified_dppr2018.Phonenum', 'modified_dppr2018.TarikhLahir','modified_dppr2018.Negeri',
  79. 'modified_dppr2018.Country', 'modified_dppr2018.postcode', 'modified_dppr2018.Ct', 'modified_dppr2018.Jantina')->get();
  80.  
  81. return datatables()->of($data)->make(true);
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement