Skip to content

Instantly share code, notes, and snippets.

@rajucs
Created July 30, 2018 07:28
Show Gist options
  • Save rajucs/afcdc3d2c428a5ad8a706ebcd8383e9c to your computer and use it in GitHub Desktop.
Save rajucs/afcdc3d2c428a5ad8a706ebcd8383e9c to your computer and use it in GitHub Desktop.
How to add sweat alert in laravel 5.4 or >5.4
Installation ->
First, pull in the package through Composer.
composer require uxweb/sweet-alert
If using laravel < 5.5 include the service provider and alias within config/app.php.
'providers' => [
UxWeb\SweetAlert\SweetAlertServiceProvider::class,
];
'aliases' => [
'Alert' => UxWeb\SweetAlert\SweetAlert::class,
];
Finally, add the Sweet Alert Javascript library through cdn link or your desktop folder
<script src="https://unpkg.com/[email protected]/dist/sweetalert2.all.js"></script>
or <script type="text/javascript" src="{{ URL::asset('js/sweetalert2.all.js') }}"></script>
and include sweetalert view
@include('sweetalert::alert')
Include the sweetalert view below the cdn link in your layout!
Usage->
Using the Facade
First import the Alert facade in your controller.
use Alert;
Within your controllers, before you perform a redirect...
public function store()
{
Alert::message('Robots are working!');
return Redirect::home();
}
Here are some examples on how you can use the facade:
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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment