Anotheruser
4 years ago

Custom Model delete()

Posted 4 years ago by Anotheruser

Hi

When I call the destroy() on a Company model my custom delete() is invoked

public function delete()
{
    .....

    // delete all Project associated with the Company
    Project::where('company_id', $this->id)->delete();

    .......

    parent::delete();
}

This deletes all Project 's just fine. However, within my Project model I have the following custom delete method

public function delete()
{   
    Contract::where('project_id', $this->id)->delete();
    
    parent::delete();
}

My problem is that when the Projects are deleted from within the Company->delete() the custom delete() doesn't appear to get called within Project - at least the Contracts being deleted from within that function don't get deleted.

Is there something obvious i'm missing?

Thanks.

Please sign in or create an account to participate in this conversation.