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