php - Custom query for database in Laravel -
first of i'm wondering if possible in laravel?
i have code:
$master_array = $_post['master_search_array'];  $count = count($master_array); $master_string = '';  for($i=0; $i<$count; $i++) {     if($master_array[$i] == "dining"){         $master_string .= "where('dining', 'dining')";     }     if($master_array[$i] == "party"){         $master_string .= "where('party','party')";     }     ....etc point }  $tours = db::table('tours')->$master_string->get();  return $tours; so @ end should this:
$tours = db::table('tours')->where('dining', 'dining)->where('party','party')->get(); how can in laravel, gives me error, no matter if pass $master_string or {{$master_string}}.
there no need master string. use query builder how it's meant used...
    $master_array = $_post['master_search_array'];      $count = count($master_array);     $query = db::table('tours');      for($i=0; $i<$count; $i++) {         if($master_array[$i] == "dining"){             $query->where('dining', 'dining');         }         if($master_array[$i] == "party"){             $query->where('party', 'party');         }     }      $tours = $query->get();      return $tours; 
Comments
Post a Comment