|
| 1 | +## SweetAlert 2 |
| 2 | +Laravel 5 Package for <a href="https://limonte.github.io/sweetalert2/">SweetAlert 2</a>. Use this package to easily show sweetalert2 prompts in your laravel app. |
| 3 | + |
| 4 | +<strong>Installation</strong> |
| 5 | + |
| 6 | +<ol> |
| 7 | + <li>Use composer to install the package<br> |
| 8 | + <pre><code> composer require softon/sweetalert </code></pre> |
| 9 | + </li> |
| 10 | + <li>(Optional for Laravel 5.5) Add the service provider to the config/app.php file in Laravel<br> |
| 11 | + <pre><code> Softon\SweetAlert\SweetAlertServiceProvider::class, </code></pre> |
| 12 | + |
| 13 | + </li> |
| 14 | + <li>(Optional for Laravel 5.5) Add an alias for the Facade to the config/app.php file in Laravel<br> |
| 15 | + <pre><code> 'SWAL' => Softon\SweetAlert\Facades\SWAL::class, </code></pre> |
| 16 | + |
| 17 | + </li> |
| 18 | + <li>Publish the config & views by running <br> |
| 19 | + <pre><code> php artisan vendor:publish </code></pre> |
| 20 | + |
| 21 | + </li> |
| 22 | +</ol> |
| 23 | + |
| 24 | +<strong>Config File:</strong> |
| 25 | + |
| 26 | +You can change the basic parameters of the package. Refer the <a href="https://limonte.github.io/sweetalert2/">SweetAlert2</a> Docs for details. |
| 27 | + |
| 28 | +<strong>View Files:</strong> |
| 29 | + |
| 30 | +This package does have its own views to be included in your templates. But if you would like to tweak it or include your own you can use the views published in the resources/views/vendor/sweetalert directory. This package also includes a SweetAlert2 CDN that you can include if you have not included the SweetAlert2 Javascript file from their website. The CDN view must be loaded first. |
| 31 | + |
| 32 | +For Inbuilt views use this in your blade templates before the closing body tag |
| 33 | +```php |
| 34 | +@include('sweetalert::cdn') |
| 35 | +@include('sweetalert::view') |
| 36 | + |
| 37 | +``` |
| 38 | + |
| 39 | +Or for the Published Views use this |
| 40 | +```php |
| 41 | +@include('vendor.sweetalert.cdn') |
| 42 | +@include('vendor.sweetalert.view') |
| 43 | +``` |
| 44 | + |
| 45 | +#Usage |
| 46 | + |
| 47 | +You may use the SWAL Facade or the swal helper function to call the methods. |
| 48 | + |
| 49 | +Showing a Message to User using the SWAL Facade:- |
| 50 | +```php |
| 51 | +use Softon\SweetAlert\Facades\SWAL; |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | +// Params: [Title,Text,Type,Options[]] |
| 56 | +SWAL::message('Good Job','You have successfully Loged In!','info'); |
| 57 | +SWAL::message('Good Job','You have successfully Loged In!','error'); |
| 58 | +SWAL::message('Good Job','You have successfully Loged In!','success',['timer'=>2000]); |
| 59 | + |
| 60 | +// For All avialable options please refer the SweetAlert 2 Docs |
| 61 | + |
| 62 | + ``` |
| 63 | + |
| 64 | +Showing a Message to User using the swal helper function:- |
| 65 | +```php |
| 66 | +swal('Your Title','Text'); |
| 67 | +swal()->message('Good Job','You have successfully Loged In!','info'); |
| 68 | +swal()->message('Good Job','You have successfully Loged In!','error'); |
| 69 | +swal()->message('Good Job','You have successfully Loged In!','success',['timer'=>2000]); |
| 70 | + ``` |
| 71 | + |
| 72 | +Message Type Can be 'warning', 'error', 'success', 'info' and 'question'. Based on this there are some convinence function that can be used instead of the message method.:- |
| 73 | +```php |
| 74 | +// Params [Title, Text, Options] |
| 75 | +swal()->warning('Good Job','You have successfully Loged In!',[]); |
| 76 | +swal()->error('Good Job','You have successfully Loged In!',[]); |
| 77 | +swal()->success('Good Job','You have successfully Loged In!',[]); |
| 78 | +swal()->info('Good Job','You have successfully Loged In!',[]); |
| 79 | +swal()->question('Good Job','You have successfully Loged In!',[]); |
| 80 | +``` |
| 81 | + |
| 82 | +To show modal which will autoclose after few seconds:- |
| 83 | +```php |
| 84 | +swal()->autoclose(2000)->message('Good Job','You have successfully Loged In!','info'); |
| 85 | +swal()->autoclose(5000)->success('Good Job','You have successfully Loged In!'); |
| 86 | +``` |
| 87 | + |
| 88 | +To show a toast modal which will autoclose after few seconds:- |
| 89 | +```php |
| 90 | +swal()->toast()->autoclose(2000)->message('Good Job','You have successfully Loged In!','info'); |
| 91 | +``` |
| 92 | + |
| 93 | +To change confirm button text:- |
| 94 | +```php |
| 95 | +swal()->button('Close Me')->message('Good Job','You have successfully Loged In!','info'); |
| 96 | + |
| 97 | +// Button Params [Button Text,Button Colour, SWAL Style Enable / Disable, Style Class for Buttons] |
| 98 | +swal()->button('Close Me','#efefef',false,'btn btn-primary')->info('Good Job','You have successfully Loged In!'); |
| 99 | +``` |
| 100 | + |
| 101 | +To change position of the modal:- |
| 102 | +```php |
| 103 | +// Possible Posions : 'top', 'top-left', 'top-right', 'center', 'center-left', 'center-right', 'bottom', 'bottom-left', or 'bottom-right' |
| 104 | +swal()->position('top')->message('Good Job','You have successfully Loged In!','info'); |
| 105 | +``` |
| 106 | + |
| 107 | +You can chain any of these methods to combine the functionality: |
| 108 | + |
| 109 | +```php |
| 110 | +swal()->position('bottom-right')->autoclose(3000)->toast()->message('This is A Custom Message'); |
| 111 | +``` |
0 commit comments