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 to get all vehicles in a specific province , but my code need to start calling from vehicle model, because I am calling many filters to Vehicles.
My code:
$p = 'Alberta'; $d = Vehicle::whereHas('province', function($q) use ($p) { $q->where('province_name', $p); return $q; })->get(); dd($d); Unfortunately getting error
Column not found: 1054 Unknown column 'dealers.province_id' in 'where clause' (SQL: select * from
vehicleswhere exists (select * fromprovinceswheredealers.province_id=provinces.idandprovince_name= Alberta))
But province_id column do exist in dealers table. How can I make it work?