Hi I am trying to get the model of a vehicle through hasOneThrough Relationship, but I am failing with the property, what am I doing wrong?
tables
vehicles |
---|
id |
color |
brand_id |
brands |
---|
id |
name |
vehicle_models |
---|
id |
name |
brand_id |
Models
Client
public function Vehicles(){
return $this->belongstoMany(Vehicle::class);
}
Vehicle
public function brand()
{
return $this->BelongsTo(Brand::class);
}
public function client(){
return $this->belongstoMany(Client::class);
}
public function vehiclemodel(){
return $this->hasOneThrough(VehicleModel::class, Brand::class,'brand_id','id','id','brand_id');
}
Brand
public function vehicles()
{
return $this->hasMany(Vehicle::class);
}
VehicleModel
public function brand()
{
return $this->hasMany(Brand::class);
}
Query
$Client = Client::find($id);
foreach($Client->vehicles->vehiclemodel as $c){
echo $c->name;
}