You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+55-38Lines changed: 55 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,75 +1,87 @@
1
1
## SweetAlert 2
2
-
Laravel 5 Package for <ahref="https://github.com/sweetalert2/sweetalert2/">SweetAlert 2</a>. Use this package to easily show sweetalert2 prompts in your laravel app.
3
2
4
-
<strong>Installation</strong>
3
+
Laravel 5 Package for [SweetAlert 2](https://github.com/sweetalert2/sweetalert2/). Use this package to easily show SweetAlert prompts in your Laravel application.
3. (Optional for Laravel 5.5) Add an alias for the Facade to the config/app.php file in Laravel<br>
20
+
21
+
```php
22
+
'SWAL' => Softon\SweetAlert\Facades\SWAL::class,
23
+
```
20
24
21
-
</li>
22
-
</ol>
25
+
4. Publish the config & views by running <br>
23
26
24
-
<strong>Config File:</strong>
27
+
```bash
28
+
$ php artisan vendor:publish
29
+
```
25
30
26
-
You can change the basic parameters of the package. Refer the <ahref="https://github.com/sweetalert2/sweetalert2/">SweetAlert2</a> Docs for details.
31
+
### View
27
32
28
-
<strong>View Files:</strong>
33
+
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.
29
34
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.
35
+
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.
36
+
37
+
For built in views, you can use this in your blade templates before the closing body tag
31
38
32
-
For Inbuilt views use this in your blade templates before the closing body tag
33
39
```php
34
-
@include('sweetalert::cdn')
40
+
@include('sweetalert::cdn') // Optional needed only if SweetAlert2 files are not inserted by the developer
35
41
@include('sweetalert::view')
36
-
42
+
@include('sweetalert::validator') // Optional needed only to show form validation errors automatically
37
43
```
38
44
39
45
Or for the Published Views use this
46
+
40
47
```php
41
-
@include('vendor.sweetalert.cdn')
48
+
@include('vendor.sweetalert.cdn') // Optional needed only if SweetAlert2 files are not inserted by the developer
42
49
@include('vendor.sweetalert.view')
50
+
@include('vendor.sweetalert.validator') // Optional needed only to show form validation errors automatically
43
51
```
44
52
45
-
#Usage
53
+
### Configuration
54
+
55
+
You can change the basic parameters of the package by referring to the [SweetAlert2](https://github.com/sweetalert2/sweetalert2/) documentations for more details.
56
+
57
+
### Usage
46
58
47
59
You may use the SWAL Facade or the swal helper function to call the methods.
48
60
49
-
Showing a Message to User using the SWAL Facade:-
61
+
Showing a Message to User using the SWAL Facade:
62
+
50
63
```php
51
64
use Softon\SweetAlert\Facades\SWAL;
52
65
53
-
54
-
55
66
// Params: [Title,Text,Type,Options[]]
56
67
SWAL::message('Good Job','You have successfully logged In!','info');
57
68
SWAL::message('Good Job','You have successfully logged In!','error');
58
69
SWAL::message('Good Job','You have successfully logged In!','success',['timer'=>2000]);
59
70
60
71
// For All available options please refer the SweetAlert 2 Docs
61
-
62
72
```
63
73
64
-
Showing a Message to User using the swal helper function:-
74
+
Showing a Message to User using the swal helper function:
75
+
65
76
```php
77
+
78
+
//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.:
66
79
swal('Your Title','Text');
67
80
swal()->message('Good Job','You have successfully logged In!','info');
68
81
swal()->message('Good Job','You have successfully logged In!','error');
69
82
swal()->message('Good Job','You have successfully logged In!','success',['timer'=>2000]);
70
83
```
71
84
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
85
```php
74
86
// Params [Title, Text, Options]
75
87
swal()->warning('Good Job','You have successfully logged In!',[]);
@@ -79,31 +91,36 @@ swal()->info('Good Job','You have successfully logged In!',[]);
79
91
swal()->question('Good Job','You have successfully logged In!',[]);
80
92
```
81
93
82
-
To show modal which will autoclose after few seconds:-
94
+
To show modal which will autoclose after few seconds:
95
+
83
96
```php
84
97
swal()->autoclose(2000)->message('Good Job','You have successfully logged In!','info');
85
98
swal()->autoclose(5000)->success('Good Job','You have successfully logged In!');
86
99
```
87
100
88
-
To show a toast modal which will autoclose after few seconds:-
101
+
To show a toast modal which will autoclose after few seconds:
102
+
89
103
```php
90
104
swal()->toast()->autoclose(2000)->message('Good Job','You have successfully logged In!','info');
91
105
```
92
106
93
-
To change confirm button text:-
107
+
To change confirm button text:
108
+
94
109
```php
95
110
swal()->button('Close Me')->message('Good Job','You have successfully logged In!','info');
96
111
97
112
// Button Params [Button Text,Button Colour, SWAL Style Enable / Disable, Style Class for Buttons]
98
113
swal()->button('Close Me','#efefef',false,'btn btn-primary')->info('Good Job','You have successfully logged In!');
99
114
```
100
115
101
-
To change position of the modal:-
102
-
```php
116
+
To change position of the modal:
117
+
103
118
// Possible Posions : 'top', 'top-left', 'top-right', 'center', 'center-left', 'center-right', 'bottom', 'bottom-left', or 'bottom-right'
104
119
swal()->position('top')->message('Good Job','You have successfully logged In!','info');
105
120
```
106
121
122
+
Possible Positions : `top`, `top-left`, `top-right`, `center`, `center-left`, `center-right`, `bottom`, `bottom-left`, or `bottom-right`
123
+
107
124
You can chain any of these methods to combine the functionality:
0 commit comments