Hello guys I am working on a project build using laravel 5.6, I want to filter results in search, based on conditions that applies to different columns from both the tables.
I have two tables one is Adverts and other is Vehicle_Specifications
Adverts has columns:
[id, user_id, category_id, status_id, promotion_id,title, description, state, city, cost, slug]
Adverts table is also related to Ad_Images table which holds all the images of the adverts according to their ids.
Vehicle_Specifications has columns:
[id, advert_id, brand, model, year, body_type, doors, color, milage, fuel_type]
Scenario: Now I want to filter data from adverts table based on status_id, state, city then get those adverts which has filters matching in vehicle_specifications table like brand = honda, model = civic etc. and also paginate the result.
Query that I have tried:
$filtered_vehicles = Ad::with('vehiclespecification')->where([['state', $state]])->whereHas('vehiclespecification', function ($query) {
$query->where('brand', 'like',$_GET['make'].'%');
})->paginate(50);
the above query does give me some results but it is not perfect. Any help would be much appreciated.
Thank you
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3jrFo0I
via IFTTT
Aucun commentaire:
Enregistrer un commentaire