I have 3 models : Vehicle, Dealer and Province
Eloquent Relationships are as follows:
Vehicle belongsTo Dealer
Dealer hasMany Vehicles
Province hasMany Dealers
Dealer belongs to Province
Province hasManyThrough Vehicles
I wanted the count of vehicles in each province with province name after applying a set of filters to the vehicles list.
My code:
$result = Vehicle::ApplyFilters($conditions)
->with(['dealer.province' => function($query) {
return $query->groupBy('province_name');
}])->get();
Unfortunately not getting desired result. It is listing the vehicles and not grouped by province.
Any idea to make it work?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire