PHPackages                             gartservice/livewire-sweet-alerts - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. gartservice/livewire-sweet-alerts

ActiveLibrary

gartservice/livewire-sweet-alerts
=================================

A Laravel Livewire package that allows you to show SweetAlert2 notifications directly from Livewire components.

v1.1.0(1y ago)04MITPHPPHP &gt;=8.3

Since Oct 22Pushed 10mo agoCompare

[ Source](https://github.com/gartservice/livewire-sweet-alerts)[ Packagist](https://packagist.org/packages/gartservice/livewire-sweet-alerts)[ RSS](/packages/gartservice-livewire-sweet-alerts/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

Livewire Sweet Alerts
=====================

[](#livewire-sweet-alerts)

A Laravel 11+ / Livewire 3 trait to easily trigger [SweetAlert2](https://sweetalert2.github.io/) modals from PHP code.

[![Livewire Sweet Alerts Demo](preview.gif)](preview.gif)

📦 Installation
--------------

[](#-installation)

```
composer require gartservice/livewire-sweet-alerts
```

⚙️ Setup
--------

[](#️-setup)

### 1. Include SweetAlert2 in your Blade layout

[](#1-include-sweetalert2-in-your-blade-layout)

If not using Vite, add this to your main layout (e.g. `resources/views/layouts/app.blade.php`):

```

```

### 2. Or install with Vite

[](#2-or-install-with-vite)

```
npm install sweetalert2
```

Then in your `resources/js/app.js`:

```
import Swal from 'sweetalert2';
window.Swal = Swal;
```

Run:

```
npm run dev
```

🚀 Usage
-------

[](#-usage)

### Add Trait to Livewire Component

[](#add-trait-to-livewire-component)

```
use Gartservice\LivewireSweetAlert\LivewireSweetAlert;

class ExampleComponent extends Component
{
    use LivewireSweetAlert;

    public function save()
    {
        $this->alert('Saved!', 'Your data was saved successfully.', 'success');
    }
}
```

### Confirm Modal Example

[](#confirm-modal-example)

```
$this->confirm(
    'Are you sure?',
    'This action cannot be undone.',
    'warning',
    'Yes, delete it!',
    'Cancel',
    'deleteConfirmed()', // Make sure this method is not public (should be protected or private)
    'cancelled()'
);
```

### Alert with Callbacks (didClose)

[](#alert-with-callbacks-didclose)

```
$this->alert(
    'Notice',
    'Check your console.',
    'info',
    [
        'didClose' => '() => { console.log("Alert was closed") }' // Must be a valid JS function string, e.g., '() => { ... }'
    ]
);
```

### Confirm Modal with Callbacks (didOpen, didClose)

[](#confirm-modal-with-callbacks-didopen-didclose)

```
$this->confirm(
    'Confirm Action',
    'Do you want to proceed?',
    'question',
    'Proceed',
    'Cancel',
    'proceedConfirmed', // Make sure this method is not public (should be protected or private)
    'cancelledAction',
    [
        'didOpen' => '() => { console.log("Opened!") }',
        'didClose' => '() => { console.log("Closed!") }'
    ]
);
```

🧪 Full Demo Example
-------------------

[](#-full-demo-example)

### Component Class

[](#component-class)

```
namespace App\Livewire;

use Livewire\Component;
use Gartservice\LivewireSweetAlert\LivewireSweetAlert;

class SweetAlertDemo extends Component
{
    use LivewireSweetAlert;

    public function showSimpleAlert()
    {
        // Any logic can be here
        $this->alert('Hello!', 'This is a basic alert.', 'success');
    }

    public function showAlertWithCallback()
    {
        $this->alert('Notice', 'Check your console after closing.', 'info', [
            'didClose' => '() => { console.log("Alert was closed!"); console.log("This is a callback function!"); }'
        ]);
    }

    public function showConfirmAlert()
    {
        // Show confirm message before processing
        $this->confirm(
            'Are you sure?',
            'This action is irreversible.',
            'warning',
            'Yes, go ahead!',
            'Cancel',
            'confirmedAction',
            'cancelledAction'
        );
    }
    // This method can be run only after confirm
    protected function confirmedAction()
    {
        // Perform any additional logic after confirmation, such as auditing user actions
        $this->alert('Confirmed', 'You agreed!', 'success');
    }

    public function cancelledAction()
    {
        // Show message if user canceled action
        $this->alert('Cancelled', 'You backed out.', 'error');
    }

    public function render()
    {
        return view('livewire.sweet-alert-demo');
    }
}
```

### Blade View

[](#blade-view)

```

    Simple Alert

    Alert with Callback

    Confirmation

    Run Action Directly

```

✅ Compatibility
---------------

[](#-compatibility)

- Laravel 11+
- PHP 8.3+
- Livewire 3+

📄 License
---------

[](#-license)

MIT License. Created by [Gartservice](https://github.com/gartservice).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance46

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

566d ago

Major Versions

v0.9 → v1.0.02024-10-23

### Community

Maintainers

![](https://www.gravatar.com/avatar/cf3f3c1d9000bddd2f29710b9352fe6514da437cb80881fafbff7b5c2310e213?d=identicon)[gartservice](/maintainers/gartservice)

---

Top Contributors

[![gartservice](https://avatars.githubusercontent.com/u/65447789?v=4)](https://github.com/gartservice "gartservice (9 commits)")

### Embed Badge

![Health badge](/badges/gartservice-livewire-sweet-alerts/health.svg)

```
[![Health](https://phpackages.com/badges/gartservice-livewire-sweet-alerts/health.svg)](https://phpackages.com/packages/gartservice-livewire-sweet-alerts)
```

###  Alternatives

[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[kirschbaum-development/commentions

A package to allow you to create comments, tag users and more

12369.2k](/packages/kirschbaum-development-commentions)[livewire-filemanager/filemanager

A simple, friendly and practical Livewire filemanager for your applications

3587.6k1](/packages/livewire-filemanager-filemanager)[calebdw/larastan-livewire

A Larastan / PHPStan extension for Livewire.

43482.4k3](/packages/calebdw-larastan-livewire)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

116.6k](/packages/tomshaw-electricgrid)[a2insights/filament-saas

Filament Saas for A2Insights

161.1k](/packages/a2insights-filament-saas)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
