PHPackages                             skyraptor/sweet-alert - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. skyraptor/sweet-alert

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

skyraptor/sweet-alert
=====================

A simple PHP package to show Sweet Alerts with the Laravel Framework

2.0.4(5y ago)121MITPHPPHP &gt;=7.0

Since Jul 11Pushed 5y agoCompare

[ Source](https://github.com/bumbummen99/sweet-alert)[ Packagist](https://packagist.org/packages/skyraptor/sweet-alert)[ RSS](/packages/skyraptor-sweet-alert/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (5)Versions (37)Used By (0)

Sweet Alert for Laravel
=======================

[](#sweet-alert-for-laravel)

[![A success alert](demos/1XySJiz.png)](demos/1XySJiz.png)

[![Build Status](https://camo.githubusercontent.com/554f140f2dbfcb4431c68e0cb708258427eeef00217ccd7eca6e1260d57e93d2/68747470733a2f2f7472617669732d63692e6f72672f62756d62756d6d656e39392f73776565742d616c6572742e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/bumbummen99/sweet-alert)[![codecov](https://camo.githubusercontent.com/b95757c364c89766a3a18aa0783646ec682ecec1d01420e12a97ea52e0a4d61b/68747470733a2f2f636f6465636f762e696f2f67682f62756d62756d6d656e39392f73776565742d616c6572742f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/bumbummen99/sweet-alert)[![StyleCI](https://camo.githubusercontent.com/1bd742d9e89ca4143c4dda09b3a9db44aabfae8a8e95bd8e9e025ff13e1b7d4d/68747470733a2f2f7374796c6563692e696f2f7265706f732f3239343231343730302f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/294214700)[![Total Downloads](https://camo.githubusercontent.com/d9a69f2d98b8420754df57e7bcfcfcdae185cf7a690f9c34d0795563c48084f0/68747470733a2f2f706f7365722e707567782e6f72672f736b79726170746f722f73776565742d616c6572742f646f776e6c6f6164732e706e67)](https://packagist.org/packages/skyraptor/sweet-alert)[![Latest Stable Version](https://camo.githubusercontent.com/27ca5c83cd1de7a34b7a84026dc5e8df53bd45376b3e6cc27a5abb5198df9410/68747470733a2f2f706f7365722e707567782e6f72672f736b79726170746f722f73776565742d616c6572742f762f737461626c65)](https://packagist.org/packages/skyraptor/sweet-alert)[![Latest Unstable Version](https://camo.githubusercontent.com/fa7c7f4c7a196c80e135bcd1f5b567202a97bdedbe2e87a6b30a1d518b9da7d7/68747470733a2f2f706f7365722e707567782e6f72672f736b79726170746f722f73776565742d616c6572742f762f756e737461626c65)](https://packagist.org/packages/skyraptor/sweet-alert)[![License](https://camo.githubusercontent.com/ab5299a3f0d53cd48eb4bdf3f7a32097017e1e8ae24f18c2c2535b7acb971c46/68747470733a2f2f706f7365722e707567782e6f72672f736b79726170746f722f73776565742d616c6572742f6c6963656e7365)](https://packagist.org/packages/skyraptor/sweet-alert)

Installation
------------

[](#installation)

You can install the package with [composer](https://getcomposer.org/download/) by using the following command:

```
composer require skyraptor/sweet-alert
```

### Laravel &lt; 5.5

[](#laravel--55)

If using Laravel &lt; 5.5 include the service provider and alias within `config/app.php`.

```
'providers' => [
    UxWeb\SweetAlert\SweetAlertServiceProvider::class,
];

'aliases' => [
    'Alert' => UxWeb\SweetAlert\SweetAlert::class,
];
```

Installing Frontend Dependencies
--------------------------------

[](#installing-frontend-dependencies)

In order for this package to work you will have to include the [SweetAlert](https://sweetalert.js.org/) JavaScript library and Stylesheets in your frontend.

### Using a CDN

[](#using-a-cdn)

```
>

    @include('sweet::alert')

```

### Using Laravel Mix

[](#using-laravel-mix)

Install using Yarn

```
yarn add sweetalert --dev
```

Install using NPM

```
npm install sweetalert --save-dev
```

Require sweetalert within your `resources/js/bootstrap.js` file.

```
// ...

require("sweetalert");

// ...
```

Then make sure to include your scripts in your blade layout. Remove the `defer` attribute if your script tag contains it, `defer` will delay the execution of the script which will cause an error as the `sweet::alert` blade template is rendered first by the browser as html.

```
>

    @include('sweet::alert')

```

Finally compile your assets with Mix

```
npm run dev
```

Usage
-----

[](#usage)

### Using the Facade

[](#using-the-facade)

First import the SweetAlert facade in your controller.

```
use SweetAlert;
```

Within your controllers, before you perform a redirect...

```
public function store()
{
    SweetAlert::message('Robots are working!');

    return Redirect::home();
}
```

Here are some examples on how you can use the facade:

```
SweetAlert::message('Message', 'Optional Title');

SweetAlert::basic('Basic Message', 'Mandatory Title');

SweetAlert::info('Info Message', 'Optional Title');

SweetAlert::success('Success Message', 'Optional Title');

SweetAlert::error('Error Message', 'Optional Title');

SweetAlert::warning('Warning Message', 'Optional Title');
```

### Using the helper function

[](#using-the-helper-function)

`alert($message = null, $title = '')`

In addition to the previous listed methods you can also just use the helper function without specifying any message type. Doing so is similar to:

`alert()->message('Message', 'Optional Title')`

Like with the Facade we can use the helper with the same methods:

```
alert()->message('Message', 'Optional Title');

alert()->basic('Basic Message', 'Mandatory Title');

alert()->info('Info Message', 'Optional Title');

alert()->success('Success Message', 'Optional Title');

alert()->error('Error Message', 'Optional Title');

alert()->warning('Warning Message', 'Optional Title');

alert()->basic('Basic Message', 'Mandatory Title')->autoclose(3500);

alert()->error('Error Message', 'Optional Title')->persistent('Close');
```

Within your controllers, before you perform a redirect...

```
/**
 * Destroy the user's session (logout).
 *
 * @return Response
 */
public function destroy()
{
    Auth::logout();

    alert()->success('You have been logged out.', 'Good bye!');

    return home();
}
```

For a general information alert, just do: `alert('Some message');` (same as `alert()->message('Some message');`).

### Using the Middleware

[](#using-the-middleware)

#### Middleware Groups

[](#middleware-groups)

First register the middleware in web middleware groups by simply adding the middleware class `UxWeb\SweetAlert\ConvertMessagesIntoSweetAlert::class` into the $middlewareGroups of your app/Http/Kernel.php class:

```
protected $middlewareGroups = [
    'web' => [
        \App\Http\Middleware\EncryptCookies::class,
        ...
        \UxWeb\SweetAlert\ConvertMessagesIntoSweetAlert::class,
    ],

    'api' => [
        'throttle:60,1',
    ],
];
```

> Make sure you register the middleware within the 'web' group only.

#### Route Middleware

[](#route-middleware)

Or if you would like to assign the middleware to specific routes only, you should add the middleware to `$routeMiddleware` in `app/Http/Kernel.php` file:

```
protected $routeMiddleware = [
    'auth' => \App\Http\Middleware\Authenticate::class,
    ....
    'sweetalert' => \UxWeb\SweetAlert\ConvertMessagesIntoSweetAlert::class,
];
```

Next step: within your controllers, set your return message (using `with()`) and send the proper message and proper type.

```
return redirect('dashboard')->with('success', 'Profile updated!');
```

or

```
return redirect()->back()->with('error', 'Profile updated!');
```

> **NOTE**: When using the middleware it will make an alert to display if it detects any of the following keys flashed into the session: `error`, `success`, `warning`, `info`, `message`, `basic`.

### Final Considerations

[](#final-considerations)

By default, all alerts will dismiss after a sensible default number of seconds.

But not to worry, if you need to specify a different time you can:

```
// -> Remember!, the number is set in milliseconds
alert('Hello World!')->autoclose(3000);
```

Also, if you need the alert to be persistent on the page until the user dismiss it by pressing the alert confirmation button:

```
// -> The text will appear in the button
alert('Hello World!')->persistent("Close this");
```

You can render html in your message with the html() method like this:

```
// -> html will be evaluated
alert('Click me')->html()->persistent("No, thanks");
```

Customize
---------

[](#customize)

### Config

[](#config)

If you need to customize the default configuration options for this package just export the configuration file:

```
php artisan vendor:publish --provider "UxWeb\SweetAlert\SweetAlertServiceProvider" --tag=config
```

A `sweet-alert.php` configuration file will be published to your `config` directory. By now, the only configuration that can be changed is the timer for all autoclose alerts.

### View

[](#view)

If you need to customize the included alert message view, run:

```
php artisan vendor:publish --provider "UxWeb\SweetAlert\SweetAlertServiceProvider" --tag=views
```

The package view is located in the `resources/views/vendor/sweet/` directory.

You can customize this view to fit your needs.

#### Configuration Options

[](#configuration-options)

You have access to the following configuration options to build a custom view:

```
Session::get('sweet_alert.text')
Session::get('sweet_alert.title')
Session::get('sweet_alert.icon')
Session::get('sweet_alert.closeOnClickOutside')
Session::get('sweet_alert.buttons')
Session::get('sweet_alert.timer')
```

Please check the CONFIGURATION section in the [website](https://sweetalert.js.org/docs/#configuration) for all other options available.

### Default View

[](#default-view)

The `sweet_alert.alert` session key contains a JSON configuration object to pass it directly to Sweet Alert.

```
@if (Session::has('sweet_alert.alert'))

  swal({!! Session::get('sweet_alert.alert') !!});

@endif
```

Note that `{!! !!}` are used to output the json configuration object unescaped, it will not work with `{{ }}` escaped output tags.

### Custom View

[](#custom-view)

This is an example of how you can customize your view to fit your needs:

```
@if (Session::has('sweet_alert.alert'))

  swal({
      text: "{!! Session::get('sweet_alert.text') !!}",
      title: "{!! Session::get('sweet_alert.title') !!}",
      timer: {!! Session::get('sweet_alert.timer') !!},
      icon: "{!! Session::get('sweet_alert.type') !!}",
      buttons: "{!! Session::get('sweet_alert.buttons') !!}",

      // more options
  });

@endif
```

Note that you must use `""` (double quotes) to wrap the values except for the timer option.

Tests
-----

[](#tests)

To run the included test suite:

```
vendor/bin/phpunit
```

Demo
----

[](#demo)

```
SweetAlert::message('Welcome back!');

return Redirect::home();
```

[![A simple alert](demos/4bvuJx9.png)](demos/4bvuJx9.png)

```
SweetAlert::message('Your profile is up to date', 'Wonderful!');

return Redirect::home();
```

[![A simple alert with title](demos/GsGOtOq.png)](demos/GsGOtOq.png)

```
SweetAlert::message('Thanks for comment!')->persistent('Close');

return Redirect::home();
```

[![A simple alert with title and button](demos/AnRGDY2.png)](demos/AnRGDY2.png)

```
SweetAlert::info('Email was sent!');

return Redirect::home();
```

[![A info alert](demos/DxKh3Yx.png)](demos/DxKh3Yx.png)

```
SweetAlert::error('Something went wrong', 'Oops!');

return Redirect::home();
```

[![A error alert](demos/pIeTEYz.png)](demos/pIeTEYz.png)

```
SweetAlert::success('Good job!');

return Redirect::home();
```

[![A success alert](demos/pQz3ijJ.png)](demos/pQz3ijJ.png)

```
SweetAlert::info('Random lorempixel.com : ')->html();

return Redirect::home();
```

[![HTML in message](demos/x44c12a.png)](demos/x44c12a.png)

```
SweetAlert::success('Good job!')->persistent("Close");

return Redirect::home();
```

[![A persistent alert](demos/dj3y95K.png)](demos/dj3y95K.png)

License
-------

[](#license)

Sweet Alert for Laravel is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 69.4% 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 ~72 days

Recently: every ~194 days

Total

27

Last Release

2068d ago

Major Versions

1.4.3 → v2.x-dev2018-07-24

PHP version history (2 changes)1.0.0PHP &gt;=5.4.0

v2.x-devPHP &gt;=7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/509a5baf8d7d8f7ae8c5b569ee81b1d04ed6af1af625696777e51e997ff9a685?d=identicon)[bumbummen99](/maintainers/bumbummen99)

---

Top Contributors

[![uxweb](https://avatars.githubusercontent.com/u/5134732?v=4)](https://github.com/uxweb "uxweb (120 commits)")[![uziel-bueno](https://avatars.githubusercontent.com/u/77310379?v=4)](https://github.com/uziel-bueno "uziel-bueno (17 commits)")[![jrean](https://avatars.githubusercontent.com/u/5646128?v=4)](https://github.com/jrean "jrean (8 commits)")[![KhaledSMQ](https://avatars.githubusercontent.com/u/8835798?v=4)](https://github.com/KhaledSMQ "KhaledSMQ (4 commits)")[![vrajroham](https://avatars.githubusercontent.com/u/12662173?v=4)](https://github.com/vrajroham "vrajroham (2 commits)")[![JoeriAben](https://avatars.githubusercontent.com/u/4263996?v=4)](https://github.com/JoeriAben "JoeriAben (2 commits)")[![georgeboot](https://avatars.githubusercontent.com/u/884482?v=4)](https://github.com/georgeboot "georgeboot (2 commits)")[![bumbummen99](https://avatars.githubusercontent.com/u/4533331?v=4)](https://github.com/bumbummen99 "bumbummen99 (2 commits)")[![meijdenmedia](https://avatars.githubusercontent.com/u/15846780?v=4)](https://github.com/meijdenmedia "meijdenmedia (1 commits)")[![mmonbr](https://avatars.githubusercontent.com/u/3525566?v=4)](https://github.com/mmonbr "mmonbr (1 commits)")[![nelson6e65](https://avatars.githubusercontent.com/u/9272498?v=4)](https://github.com/nelson6e65 "nelson6e65 (1 commits)")[![ronydebnath](https://avatars.githubusercontent.com/u/10370201?v=4)](https://github.com/ronydebnath "ronydebnath (1 commits)")[![ssfinney](https://avatars.githubusercontent.com/u/1596394?v=4)](https://github.com/ssfinney "ssfinney (1 commits)")[![thewebartisan7](https://avatars.githubusercontent.com/u/57477934?v=4)](https://github.com/thewebartisan7 "thewebartisan7 (1 commits)")[![tomopongrac](https://avatars.githubusercontent.com/u/25442485?v=4)](https://github.com/tomopongrac "tomopongrac (1 commits)")[![TortleWortle](https://avatars.githubusercontent.com/u/1979893?v=4)](https://github.com/TortleWortle "TortleWortle (1 commits)")[![LespiletteMaxime](https://avatars.githubusercontent.com/u/2920479?v=4)](https://github.com/LespiletteMaxime "LespiletteMaxime (1 commits)")[![backstageel](https://avatars.githubusercontent.com/u/1692858?v=4)](https://github.com/backstageel "backstageel (1 commits)")[![davidcb](https://avatars.githubusercontent.com/u/1170269?v=4)](https://github.com/davidcb "davidcb (1 commits)")[![djsigfried56](https://avatars.githubusercontent.com/u/1375528?v=4)](https://github.com/djsigfried56 "djsigfried56 (1 commits)")

---

Tags

laravelnotifieralertsweet

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/skyraptor-sweet-alert/health.svg)

```
[![Health](https://phpackages.com/badges/skyraptor-sweet-alert/health.svg)](https://phpackages.com/packages/skyraptor-sweet-alert)
```

###  Alternatives

[uxweb/sweet-alert

A simple PHP package to show Sweet Alerts with the Laravel Framework

8251.3M6](/packages/uxweb-sweet-alert)[realrashid/sweet-alert

Laravel Sweet Alert Is A Package For Laravel Provides An Easy Way To Display Alert Messages Using The SweetAlert2 Library.

1.2k2.9M21](/packages/realrashid-sweet-alert)[prologue/alerts

Prologue Alerts is a package that handles global site messages.

3486.1M30](/packages/prologue-alerts)[masmerise/livewire-toaster

Beautiful toast notifications for Laravel / Livewire.

505550.3k6](/packages/masmerise-livewire-toaster)

PHPackages © 2026

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