Skip to content
This repository has been archived by the owner on Jan 3, 2020. It is now read-only.

faustbrian-archives/laravel-sweet-alert

Repository files navigation

Laravel Sweet-Alert

Build Status PHP from Packagist Latest Version License

Installation

Requirements

SweetAlert by t4t5

Require this package, with Composer, in the root directory of your project.

$ composer require artisanry/sweet-alert

And then include the service provider within app/config/app.php.

Artisanry\SweetAlert\SweetAlertServiceProvider::class

Usage

<!doctype html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Laravel PHP Framework</title>
        <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/sweetalert/1.0.1/sweetalert.min.css">
    </head>

    <body>
        <div class="container">
            <h1>My Page!</h1>
        </div>

        <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"></script>
        <script src="//cdnjs.cloudflare.com/ajax/libs/sweetalert/1.0.1/sweetalert.min.js"></script>
        @include('sweet::alert')
    </body>
</html>

Message (Defaults to Info)

sweet('Welcome aboard!');

return redirect()->route('dashboard');

Success

sweet()->success('You successfully read this important alert message.');

return redirect()->route('dashboard');

Info

sweet()->info('This alert needs your attention, but it\'s not super important.');

return redirect()->route('dashboard');

Warning

sweet()->warning('Better check yourself, you\'re not looking too good.');

return redirect()->route('dashboard');

Error

sweet()->error('Change a few things up and try submitting again.');

return redirect()->route('dashboard');

Build your own Alert

sweet()->config('title', 'Are you sure?')
       ->config('text', 'You will not be able to recover this imaginary file!')
       ->config('type', 'warning')
       ->config('showCancelButton', true)
       ->config('confirmButtonColor', '#DD6B55')
       ->config('confirmButtonText', 'Yes, delete it!')
       ->config('cancelButtonText', 'No, cancel plx!')
       ->config('closeOnConfirm', false)
       ->config('closeOnCancel', false)
       ->config('showConfirmButton', true)
       ->config('timer', null)
       ->callback('function(isConfirm) {
           if (isConfirm) {
               swal("Deleted!", "Your imaginary file has been deleted.", "success");
           } else {
               swal("Cancelled", "Your imaginary file is safe :)", "error");
           }
       }')
       ->commit();

return redirect()->route('dashboard');

Testing

$ phpunit

Security

If you discover a security vulnerability within this package, please send an e-mail to hello@basecode.sh. All security vulnerabilities will be promptly addressed.

Credits

This project exists thanks to all the people who contribute.

License

Mozilla Public License Version 2.0 (MPL-2.0).