devhereco/livewire-delete-confirmation

A Laravel package for easily handling the deletion of Eloquent models with confirmation and success/error messaging.

1.0 2023-10-23 04:03 UTC

This package is auto-updated.

Last update: 2024-04-23 05:21:14 UTC


README

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.

Installation

To get started with Livewire Confirm Delete, you can install it via Composer:

composer require devhereco/livewire-delete-confirmation

Package Dependencies

Please make sure to include the following package dependencies in your Laravel project as they are required for Livewire Confirm Delete to work:

  1. jantinnerezo/livewire-alert ^3
  2. livewire/livewire ^3

Usage

  1. Create a Livewire Component: that extends 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');
    }
}
  1. Configure Your Blade View: In your Blade view for the Livewire component, you can display your model records and add a button or trigger that calls the 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.

  1. Confirmation Dialog: When you call the destroy method, a confirmation dialog will appear, prompting the user to confirm the deletion.
  2. Success/Error Messages: After the deletion process is completed, Livewire Confirm Delete provides success and error messages, giving feedback to the user.

License

This package is open-sourced software licensed under the MIT License.

Credits

Livewire Confirm Delete is developed and maintained by Mohammed B. Copyright ©2023 Development Here.