We are now ready to complete our delete endpoint. As per the last few tests. Let’s copy the ShowCest test file and paste it back. Save it as the DeleteCest.
We need to create a record to delete, so we can keep this have(). We can get rid of the structure we created. We need to change to the action to Delete. We have to send the id of the record we wish to delete.
For our assertions, we need to use the assertion “dontSeeRecord”. Let’s run our tests, notice it will fail. Let’s update our controller method.
The delete process is very simple with Laravel. All we need to do is type Post::destroy($id);
For now, let’s return a success message.
The controller part of this action is really simple. We can use the destroy() method from Laravel to find and delete the record from the database. Let’s just return success as a string for now.
Let’s run our tests again. The should all pass. Good, they do. Don’t forget to run your full API test suite.
Watch next video here:
• Part 16 - Complete our Update endpoint [Ho...
Watch this course in full here:
• How to use TDD to build a REST API in Lara...
Laravel Tutorials:
• Laravel PHP Tutorials
2 - 3 min Developer Quick Tips Series:
https://www.youtube.com/playlist?list... this course in full here:
• How to use TDD to build a REST API in Lara...