In this article you can find a really good explanation of PATCH request.
What's the differences between PUT and PATCH?
Question speaks for itself. I understand the PUT method (as much as any semi-notive can). But how is PATCH any different? I haven't worked with this before I met Laravel. What's you guys take? Real world examples if possible.
This question relates to the general differences and how PATCH is used in Laravel itself.
Something else to consider here is the spec which relates directly to relationships and also some eloquent defaults:
PUT = replace the ENTIRE RESOURCE with the new representation provided (no mention of related resources in the spec from what i can see)
PATCH = replace parts of the source resource with the values provided AND|OR other parts of the resource are updated that you havent provided (timestamps) AND|OR updating the resource effects other resources (relationships)
From a laravel / Eloquent point of view its almost impossible to use a PUT request if following the spec as YOU dont/wont send created_at and updated_at data when trying to update the resource, which you would need to, to satisfy the spec.
Think of it this way:
$resource = Model::findOrFail($id);
$resource->fill($request->only([.....]));
$resource->save();
This MUST be a patch request as calling save will update the timestamps in the db without you providing it in the request. (asuming you use timestamps on the model.
Whereas:
DB:table('tablename')->where('id', $id)->delete();//we do this to ensure the entire dataset is replaced
DB:table('tablename')->insert($request->except('_token'));//this must also contain the id
would be a PUT request as you are replacing the entire row/resource with whats provided in the request.
Please or to participate in this conversation.