PHP code example of lara-pack / livewire-sweetalert

1. Go to this page and download the library: Download lara-pack/livewire-sweetalert library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lara-pack / livewire-sweetalert example snippets


use LaraPack\LivewireSweetalert\Alert;
use Livewire\Component;

class CreateUser extends Component
{
    public function save()
    {
        // Save logic...

        Alert::success($this, 'Success!', 'User data has been saved.');
    }

    public function handleError()
    {
        Alert::fail($this, 'Failed!', 'An error occurred while processing data.');
    }
}

use LaraPack\LivewireSweetalert\Alert;
use Livewire\Component;

class UserTable extends Component
{
    public function deleteConfirm($id)
    {
        Alert::confirmation(
            $this,
            Alert::ICON_WARNING,
            'Are you sure?',
            'Deleted data cannot be recovered!',
            'delete', // Event name if confirmed (Yes)
            'cancelDelete', // Event name if cancelled (No)
            'Yes, delete it!', // Confirmation button text (Optional)
            'Cancel' // Cancel button text (Optional)
        );
    }

    #[On('delete')]
    public function delete()
    {
        // Deletion logic...
        Alert::success($this, 'Deleted!', 'Data has been successfully deleted.');
    }

    #[On('cancelDelete')]
    public function cancelDelete()
    {
        // Optional: Logic if cancelled
    }
}