Deleting related records in Laravel 5.1 (Eloquent ORM)

Viewed 939

I have customers model, which hasMany Locations, and Locations hasMany contacts.

I want to delete the Customer and all its locations and contacts.

Now below code removes the locations successfully :

$customer = Customer::find($id);
$customer->locations()->delete();

But I want to remove the Contacts as well.

Ideally I want the code like :

$customer->locations()->contacts()->delete();

Is it possible??

2 Answers
Related