Courses

Vue.js 3 + Laravel 11 + Vite: SPA CRUD

Delete Post with Confirmation Modal

Summary of this lesson:
- Implementing post deletion endpoint
- Creating delete confirmation modal
- Handling successful deletion feedback
- Managing error states for deletion

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.

delete modal confirmation


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...

The full lesson is only for Premium Members.
Want to access all 27 lessons of this course? (115 min read)

You also get:

  • 69 courses (majority in latest Laravel 11)
  • Premium tutorials
  • Access to repositories
  • Private Discord