Pre-requisites
We'll assume 3 things:
- That the model was created using the approach in this blog post.
- That the route was created using the approach in this blog post.
- That a migration file has been set using this blog post.
- That an Eloquent API Resource has been set up using this blog post.
Now open the YourController.php.
Develop the function destroy()
like this:
public function destroy(YourModel $yourmodel)
{
$yourmodel->delete();
return response()->noContent();
}
To test this in Postman, you'll need to send a DELETE request with the URL of http://localhost/api/yourcontroller/1
In the Headers tab add the key Accept and the value of application/json
In the body select none instead of raw.
Try using an empty object to see if the API returns the validation message.
That should work.
No comments:
Post a Comment