R
R
Roman2019-02-14 19:57:48
Sublime Text
Roman, 2019-02-14 19:57:48

“Soft” removal of many-to-many relationships in Laravel - how to implement it correctly?

Share your experience - how do you implement "soft" removal of many-to-many relationships in Laravel?
I really don't want to reinvent the wheel :)
I want to be able to delete links (for example, toggle using toggle()), but at the same time be able to display them as a history, be able to resume deleted ones, etc.
How do you usually implement something like this?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jazzus, 2019-02-14
@procode

In the Pivot table, you can make the field Active true/false. This is how I implemented the deactivation of user roles with the possibility of restoring them, displaying history, etc.

$user->roles()->updateExistingPivot($id, ['active' => false]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question