i have 4 models which are related with each other.. 1st Model: school:
public function contactpersons()
{
return $this->hasMany(ContactPerson::class, 'school_id', 'id');
}
2nd Model: ContactPerson:
public function addresses()
{
return $this->belongsToMany(Address::class, 'address_contact_person', 'contact_person_id', 'address_id');
}
3rd Model: Address:
public function contactPersonAddresses()
{
return $this->belongsToMany(ContactPerson::class, 'address_contact_person', 'address_id', 'contact_person_id');
}
4th model: pivot table
AddressContactPerson:
Now the question is .. i want my records of Address and AddressContactPerson to be deleted when i delete the contact person . i tried with firing delete events but couldnt make it. the events were not triggerd .. i have to delete these records from School Model.. $school->contactpersons()->delete(); and i have softDeletes on every Models. this will only delete contactpersons record not the 'Address' and AddressContactPerson table..