"A vehicle_type has many extras and a extra belongs to an extra_type"
I did setup a pivot table for this however looking at it, I would need to find a belongstomany relationship for this to work with the attach method. Can anyone advise on the above?
@Sam if vehicle_type(id,....) has one-to-many relationship with extra(id,vehicle_type_id, ....) table and extra table has one-to-one relationship with extra_type(id,extra_id), then Extra.php model:
class Extra extends Model
{
public function VehicleType (){
return $this->belongsTo(VehicleType::class);
}
public function ExtraType (){
return $this->hasOne(ExtraType::class);
}
}
VehicleType model:
class VehicleType extends Model
{
public function extras(){
return $this->hasMany(Extra::class);
}
}
ExtraType model:
class ExtraType extends Model
{
public function extra(){
return $this->belongsTo(Extra::class);
}
}