sudam-shrestha/sudam-sweet-alert

This is my package sudam-sweet-alert

Maintainers

Package info

github.com/sudam-shrestha/sudam-sweet-alert

pkg:composer/sudam-shrestha/sudam-sweet-alert

Transparency log

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-master 2026-07-13 16:10 UTC

This package is not auto-updated.

Last update: 2026-07-13 22:36:16 UTC


README

Latest Version on Packagist GitHub Tests Action Status Total Downloads

A modern, actively maintained SweetAlert2 wrapper for Laravel 12. Fire beautiful modal alerts and toasts straight from your controllers using session flash data — no manual JS wiring required.

Built as a fresh alternative to older SweetAlert packages that are no longer maintained.

Features

  • Simple, chainable API: success(), error(), warning(), info(), question(), toast()
  • Built-in toast notifications with sensible defaults (top-right, auto-dismiss)
  • Configurable close button, colors, background, and animation on every alert
  • Per-call option overrides — any SweetAlert2 option can be passed through
  • Zero database/migrations required — pure session flash, works out of the box

Installation

You can install the package via composer:

composer require sudam-shrestha/sudam-sweet-alert

Publish the config file with:

php artisan vendor:publish --tag="sudam-sweet-alert-config"

This is the contents of the published config file:

return [
    // Modal alert defaults
    'position' => 'center',
    'timer' => null,
    'show_confirm_button' => true,

    // Toast defaults
    'toast_position' => 'top-end',
    'toast_timer' => 3000,

    // Design — applies to both modals and toasts
    'show_close_button' => true,
    'confirm_button_color' => '#3085d6',
    'cancel_button_color' => '#d33',
    'background' => null,
    'text_color' => null,
    'buttons_styling' => true,
    'custom_class' => [],

    'cdn' => 'https://cdn.jsdelivr.net/npm/sweetalert2@11',
];

Optionally, publish the views to customize the alert markup:

php artisan vendor:publish --tag="sudam-sweet-alert-views"

Finally, add this once to your main layout, right before </body>:

@include('sudam-sweet-alert::alert')

Usage

Import the facade:

use Sudam\SudamSweetAlert\Facades\SudamSweetAlert;

Modal alerts

SudamSweetAlert::success('Saved!', 'Your changes have been saved.');
SudamSweetAlert::error('Failed', 'Something went wrong.');
SudamSweetAlert::warning('Careful', 'This action cannot be undone.');
SudamSweetAlert::info('Heads up', 'Here is something you should know.');
SudamSweetAlert::question('Are you sure?', 'This will delete the record.');

return redirect()->back();

Toast notifications

SudamSweetAlert::toast('success', 'Saved successfully!');

By default, toasts appear top-right and auto-dismiss after 3 seconds.

Overriding options per call

Any SweetAlert2 option can be passed as the last argument:

SudamSweetAlert::error('Failed', 'Could not save record.', [
    'position' => 'bottom-start',
    'timer' => 5000,
    'showCloseButton' => false,
]);

Chainable helpers

SudamSweetAlert::success('Saved!')
    ->timer(4000)
    ->position('top-end')
    ->showCloseButton(false);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.