I have a Users
and a Groups
table in Laravel's Eloquent ORM. There can be multiple users in a group and a user can be in multiple groups, so I use a pivot table to realize the many-to-many relationship. In real, the relationship isn't many-to-many because every user can be in only one group, but the system was designed this way. I soft delete the rows in the Users
table so if needed I can restore users later.
The problem is that when I delete a user, the system automatically delete the entry in the pivot table too. This is always one entry. I didn't set it to behave like this, only added the protected $softDelete = true;
line to the Users
model, so I don't understand why the system automatically delete the pivot entries.
I don't want to soft delete the pivot entries, I want to soft delete only and exclusively the users, and the system shouldn't touch anything else.
I could create my own delete function that set the deleted_at
variable to the actual time but this way I couldn't simply turn of the soft delete by changing the true
to false
if I need this.
Why does the system automatically delete the pivot entries, and how can I turn off this behavior?