Now that we can create and edit posts, let's make a delete post action, with the confirmation modal. For the confirmation modal, we will again use the sweetalert2.
First, let's add a new destroy
method in the PostController
. Don't forget that we don't need to add any additional routes for this Controller methods, because all the routes come from the Route::apiResource()
that we added earlier in the routes/api.php
.
app/Http/Controllers/Api/PostController.php:
class PostController extends Controller{ // ... public function destroy(Post $post) { $post->delete(); return response()->noContent(); }}
What to return in this method? It is an open question. It's a common practice to return nothing because the record is deleted. That response()->noContent()
would return 204 HTTP Status Code.
Now in the posts Composable, we need to add a new...