mardi 8 mars 2016

Deleting related records in Laravel 5.1 (Eloquent ORM)

I have customers model, which hasMany Locations, 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??



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire