Germey / LaravelSweetAlert by Germey

Sweet Alert Extension used on Laravel
25
1
1
Package Data
Maintainer Username: Germey
Maintainer Contact: cqc@cuiqingcai.com (Germey)
Package Create Date: 2016-07-29
Package Last Update: 2016-07-29
Language: CSS
License: MIT
Last Refreshed: 2024-04-27 03:00:32
Package Statistics
Total Downloads: 25
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 1
Total Watchers: 1
Total Forks: 2
Total Open Issues: 0

Sweet Alert for Laravel

Installation

First, pull in the package through Composer.

"require": {
    "germey/sweetalert": "dev-master"
}

If using Laravel 5, include the service provider within config/app.php.

'providers' => [
    Germey\SweetAlert\SweetAlertServiceProvider::class
];

And, for convenience, add a facade alias to this same file at the bottom:

'aliases' => [
    'SweetAlert' => Germey\SweetAlert\SweetAlert::class
];

Usage

With the Facade

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

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

    return Redirect::home();
}

With the Helper

  • 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');).

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

But no fear, 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");

Finally, to display the alert in the browser, you may use (or modify) the view that is included with this package. Simply include it to your layout view:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="css/sweetalert.css">
</head>
<body>

    <div class="container">
        <p>Welcome to my website...</p>
    </div>

    <script src="js/sweetalert.min.js"></script>

    <!-- Include this after the sweet alert js file -->
    @include('sweetalert::alert')

</body>
</html>