I want sync some relation in User's Table and I don't want to Laravel delete the row, I want make some updates on that row (Like fill the deleted_at), I searched so far and only solution i found is that to override sync method.
So how i can override the sync method to update the row?
Or whats another solution for this problem?
EDITED: I know the problem is with detach
method, If i could override the detach
It will be solved!
Thanks
Soft delete hides information from end-user or flags data as deleted while it still remains visible or active in your database. To perform soft delete in Laravel, you need to have a deleted_at column that should be set to default null , as it should be of timestamp data type in the model.
To delete all records on the pivot table for a model, you may use the detach method: User::find(1)->roles()->detach();
The advantage of soft-delete concept is, as you never physically delete the data, there is no risk of loss of data when something goes wrong (with the delete action, not with your code). It's easy to get back the record by just changing the flag.
Force Delete (Permanently) If we want to delete permanently, we have this option: Product::find($id)->forceDelete(); To delete from soft-deleted (trashed) data, we need to write code like: Product::onlyTrashed()->find(2)->forceDelete(); We can also set conditions at the time of deleting data from the trash.
I think you were looking for this method.
$user->your_relation()->updateExistingPivot($userid, ['deleted_at' => $date]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With