| Install | |
|---|---|
composer require devhereco/livewire-delete-confirmation |
|
| Latest Version: | 1.0 |
Livewire Confirm Delete is a Laravel package that simplifies the process of confirming and deleting Eloquent model records with ease. It seamlessly integrates with the Livewire framework and provides a convenient way to handle model deletion while displaying confirmation dialogs and success/error messages.
To get started with Livewire Confirm Delete, you can install it via Composer:
composer require devhereco/livewire-delete-confirmation
Please make sure to include the following package dependencies in your Laravel project as they are required for Livewire Confirm Delete to work:
ConfirmDeleteComponent. You can define the Eloquent model you want to work with and customize your component as needed. For example:<?php
namespace App\Livewire;
use devhereco\LivewireConfirmDelete\ConfirmDeleteComponent;
class ProductComponent extends ConfirmDeleteComponent
{
protected $model = Product::class;
public function render()
{
return view('livewire.product-component');
}
}
destroy method from ConfirmDeleteComponent. Here's an example of how you can do this:<!-- Displaying Model Records -->
@foreach ($products as $product)
<div class="product">
<h2>{{ $product->name }}</h2>
<!-- Add a Delete Button -->
<button wire:click="destroy({{ $product->id }})">Delete</button>
</div>
@endforeach
In this example, we loop through a collection of products and display them. For each product, a "Delete" button is added with a Livewire click event to trigger the destroy method with the product's ID as a parameter. When the button is clicked, the confirmation dialog will appear.
destroy method, a confirmation dialog will appear, prompting the user to confirm the deletion.This package is open-sourced software licensed under the MIT License.
Livewire Confirm Delete is developed and maintained by Mohammed B. Copyright ©2023 Development Here.