Repolode
realrashid

realrashid/sweet-alert

A Laravel package that replaces JavaScript popup boxes with SweetAlert2-based alerts, toasts and input prompts via a fluent PHP API.

Stars
1,157
Forks
166
Open issues
9
Last commit
22 days ago

What is it?

Laravel SweetAlert is a Laravel package that replaces native JavaScript popup boxes with SweetAlert2 dialogs. Developers trigger alerts from PHP controllers using a chainable builder API, and the alerts render in the browser once the page loads.

The package provides three builders: AlertBuilder for modal dialogs, ToastBuilder for small notifications, and InputBuilder for prompts that collect user input. It includes PHP 8.3+ enums for alert types, input types and positions, and a global alert() helper. Integrations cover Blade layouts, Livewire via a trait that dispatches browser events, and Inertia.js through middleware.

The package also offers guarded actions: a data-confirm attribute on links or forms asks the user to confirm before the action proceeds, without custom JavaScript. A built-in artisan command can migrate a v7 codebase to v8, with a dry-run option to preview changes.

Key features

  • 01Fluent builder API for alerts, toasts and input prompts
  • 02Blade directive for rendering alerts in layouts
  • 03Livewire trait for dispatching alerts as browser events
  • 04Inertia.js middleware for sharing alerts with Vue or React
  • 05data-confirm attribute for guarded links and forms
  • 06artisan command to upgrade from v7 with a dry-run mode

Use cases

  • Showing success or error messages after form submissions in a Laravel app
  • Asking users to confirm destructive actions like delete links
  • Displaying toast notifications from Livewire components
  • Collecting simple user input through a modal prompt

Quick start

  1. 1

    Install the package with Composer

    composer require realrashid/sweet-alert
  2. 2

    Run the package install command

    php artisan alert:install
  3. 3

    Add the @sweetAlert Blade directive to your layout

Things to know

  • Requires PHP 8.3+ and Laravel, so it does not suit other stacks.

Topics

#laravel#php#popup#dialog#sweetalert2#toast#livewire#inertia#confirmation-dialog#laravel-package

FAQ

What is sweet-alert?
A Laravel package that replaces JavaScript popup boxes with SweetAlert2-based alerts, toasts and input prompts via a fluent PHP API. Laravel SweetAlert is a Laravel package that replaces native JavaScript popup boxes with SweetAlert2 dialogs. Developers trigger alerts from PHP controllers using a chainable builder API, and the alerts render in the browser once the page loads.
Is sweet-alert free to use? What license does it have?
sweet-alert is open source under the MIT license. Check the license terms before using it in commercial products.
Is sweet-alert still maintained?
Actively maintained. The last commit to sweet-alert was on Oct 16, 2026.
What can I use sweet-alert for?
Showing success or error messages after form submissions in a Laravel app Asking users to confirm destructive actions like delete links Displaying toast notifications from Livewire components Collecting simple user input through a modal prompt
How do I install sweet-alert?
Install the package with Composer: composer require realrashid/sweet-alert Run the package install command: php artisan alert:install Add the @sweetAlert Blade directive to your layout
Where can I get sweet-alert?
The source code and installation instructions are on GitHub: https://github.com/realrashid/sweet-alert

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects