I have to soft delete a user and specify the reason why he has been deleted. The reason is required, otherwise I cannot soft delete the user.
The soft delete is done via an HTTP DELETE request.
But with an HTTP DELETE request, it's not possible to add a body to the request.
So what could be the solution to soft delete a user and save a reason to this deletion in another table, given that the reason is required to be able to soft delete the user.
You can't send http delete unless this is from an API call? Normal web form deletes have to be post with hidden delete _method field. You can pass a body here.
If via API, you would have to url encode the reason and add it to the query string I think.
@vincent15000 its not much of a stretch to say actually you are patching the user to 'inactive' by soft deleting since you are not actually destroying the record.
Depends how much you care about semantics and REST principles.
@Snapey Well ... yes ... about semantics, I would say that a soft delete isn't a delete, it's rather an update of the deleted_at field.
What's the best pratice in Laravel for doing soft deletes ? Via an PATCH request or a DELETE request ?
Some members of the teams in which I work like to think that a soft delete should be a PATCH request. I agree with because the model isn't really deleted.
@jlrdw It's probably a good idea. In this case I can add a body to the request to pass the reason of the deletion.
What's the real difference between PUT and PATCH ?
I read that a PUT request is to replace all the fields whereas a PATCH request to merge the request with the existing datas. But in pratice it could be rather different because I could use a DELETE request to create a new model and not the delete one (sure which has no sense ;)).
Is there really a good reason to use PATCH instead of PUT ? Or i it just to respect a certain semantic (which is already a good reason) ?
@jlrdw@snapey Finally it was easier to write a new endpoint to post the reason just after having deleted the user. And the frontend will check that the connected user has explained the reason before deleting the user.