2017 © Pedro Peláez
 

library sweetalert

Sweet Alert Extension used on Laravel

image

germey/sweetalert

Sweet Alert Extension used on Laravel

  • Friday, July 29, 2016
  • by Germey
  • Repository
  • 1 Watchers
  • 1 Stars
  • 19 Installations
  • CSS
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Sweet Alert for Laravel

Installation

First, pull in the package through Composer., (*1)

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

If using Laravel 5, include the service provider within config/app.php., (*2)

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

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

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

Usage

With the Facade

Within your controllers, before you perform a redirect..., (*4)

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:, (*5)

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

Like with the Facade we can use the helper with the same methods:, (*6)

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..., (*7)

/**
 * 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');)., (*8)

By default, all alerts will dismiss after a sensible default number of seconds., (*9)

But no fear, if you need to specify a different time you can:, (*10)

    // -> 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:, (*11)

    // -> 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:, (*12)

<!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>

The Versions

29/07 2016

dev-master

9999999-dev

Sweet Alert Extension used on Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Uziel Bueno