Advertisement
ayeniblessing

search

Nov 4th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. public function search(Request $request)
  2. {
  3.  
  4. $validator = \Validator::make($request->all(), [
  5.  
  6. 'state' => 'required',
  7. 'lga' => 'required',
  8. 'blood_type' => 'required',
  9. 'pints' => 'required',
  10.  
  11. ]);
  12.  
  13. if($validator->fails())
  14. {
  15. return $this->errorUnauthorized('Ensure you fill all field don\'t leave any empty');
  16. }
  17.  
  18. $query = $request->all();
  19.  
  20. if ($query) //$query is an array, you might want to do if(count($query) > 0);
  21. {
  22. // $blood_bank = Search::where('state_id', 'LIKE', '%' . $query . '%')
  23. //->orWhere('lga_id', 'LIKE', '%' . $query . '%')
  24. //->get();
  25. /* Using and might be better here if you want exact matches of all four search criteria */
  26. $state = DB::table('state')->where()
  27.  
  28. $blood_bank = ::where('state_id', $query['state'])
  29. ->where('lga_id', $query['lga'])
  30. ->where('blood_type', 'like', '%'. $query['blood_type]')
  31. ->where(pints, '>=', $query['pints'])->get();
  32.  
  33.  
  34. return response()->json(compact('blood_bank'));
  35. }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement