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...
Great course so far.
I have a question, in the file resources/js/composables/posts.js in the deletePost method, Why did you do: router.push({ name: 'posts.index' }) if we are in that page? I commented that line and it still working. Is there any special reason? thanks
This reload the page and refreshes the table without the deleted row.
I thought the page was refreshed by getPosts()