Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Products Delete and Multi-Delete

Premium
4 min read

In this lesson, we will delete products one by one, or by selecting and deleting in bulk. In this, we will use the same sweetalert2 package to show confirmation, as we used in categories.

First, let's make deletion work by deleting a single product, which will be identical to what we did with categories. We will start by adding action to the Delete button.

resources/views/livewire/products-list.blade.php:

<button wire:click="deleteConfirm('delete', {{ $product->id }})" class="px-4 py-2 text-xs text-red-500 uppercase bg-red-200 rounded-md border border-transparent hover:text-red-700 hover:bg-red-300">
Delete
</button>

Now, we need to add a listener and deleteConfirm() with delete() methods to the Livewire component...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

A
Alin ✓ Link copied!

I am a newbie so sorry if i ask ridicolous questions. What are the advantages of using a computed property for selectedCount(for disabling the Delete Bulk button) VERSUS Using directly count($selected) in the view?

M
Modestas ✓ Link copied!

Not really an advantage/disadvantage here. It's just a habbit you can have to also prevent deleting with more conditions.

If you moved that to the view - adding a condition would mean modifying view code, but when it's a property - you can simply add it there and that's it.

But both options are valid.

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.