Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0
Last updated 2 years ago.
0

For many-to-many, calling detach with no arguments will detach all:

$category->subscribers()->detach();

You can also use sync to override the entire collection of models and replace it with an empty list:

$category->subscribers()->sync([]);

Both are covered in the docs on many-to-many, but it's very easy to miss a lot of the variants (I don't think that many people even know about sync, for example).

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ErikEklund erikeklund Joined 14 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.