I think you should use orWhere in the where function!
Like this: $q->orWhere('restaurants_symbols.symbol_id', $s);
@tavicu if I do $q->orWhere() or $q->whereIn() I don't get fixed results and what I mean by that is that if I select two checkboxes with "value1" and "value2" I get the restaurants that don't have "value2" but have "value1" as well. So what I'm looking for is to get only the restaurants with the selected values.
You need to replace "where" with "whereIn". http://laravel.com/docs/5.0/queries look at section: Using Where In With An Array
@talevskiigor as I said in my comment above $q->whereIn() will bring back restaurants that don't contain all the selected values.
Have you guys had this issue before? is it a database design problem or what other ways will it be to fix this Advanced Search Filter?
You can always use DB::raw() as workaround.... i think something like this will work cos you needt results where have all selected values:
$results = DB::table('restaurants')
->select('restaurants.id as restaurantId',
'restaurants.image_id as imageId',
'restaurants.name as restaurantName',
'restaurants.slug as restaurantSlug',
'restaurants.description as restaurantDescription',
'website', 'nutrition', 'order_online', 'history', 'contact', 'email', 'location')
->leftJoin('restaurants_symbols', 'restaurants_symbols.restaurant_id', '=', 'restaurants.id')
->leftJoin('restaurants_locations', 'restaurants_locations.restaurant_id', '=', 'restaurants.id');
$results->where('restaurants_locations.city_index', $city);
foreach($symbols as $s) {
$results->where('restaurants_symbols.symbol_id', $s);
}
$results->groupBy('restaurants_symbols.restaurant_id');
return $results->get();
@talevskiigor still the same results. If I check only 1 box is working, once I check more than 1 brings back empty array. I don't know if this is related to laravel or I'm doing something wrong here
yeh...the groupBy is the actual problem. try to group by simbol_id or other field...
test with raw sql ..one you get proper results you can easy re-factory to be in DB::
@talevskiigor I've tried only to get the symbols and still the same results, I'm running out of time with this project and I can't see any solution for this feature :(
$qry = DB::table('restaurants_symbols');
$symbols = $input['symbol'];
foreach($symbols as $s) {
$qry->where('symbol_id', $s);
}
return $qry->get();
Note: that all the values in the checkboxes are available in the database, I've double checked 20 times
Note2: I've tried raw query as well and still same results
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community