Using soft-deletes in Laravel 5.4. When I try to create an record that already has been created but soft-deleted I get the message "The xxx has already been taken". What is the best way to be able handle the event when a user attempts to save a record that has already has been soft deleted?
I have been trying to capture this event in the store method of the controller but the store method does not get called if the record already exists - AFAIK.
In my use case I have radios that can be associated to only one user at a time but can be unassigned eg soft-deleted and then reassigned to another user in the future.
You can restore()
to restore a soft deleted model:
App\User::withTrashed()->where('id', $user_id)->restore();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.