Skip to content

Commit 11683c3

Browse files
committed
feat: add service provider that boots a template
1 parent 4333b06 commit 11683c3

File tree

5 files changed

+41
-15
lines changed

5 files changed

+41
-15
lines changed

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,24 @@ npm install sweetalert2
77
composer require sweetalert2/laravel
88
```
99

10-
2. Add global `window.Swal` to your global JS (usually it's `resources/js/app.js` file):
10+
2. Publish the package assets
11+
12+
```sh
13+
php artisan vendor:publish --tag=sweetalert2
14+
```
15+
16+
3. Add global `window.Swal` to your global JS (usually it's `resources/js/app.js` file):
1117

1218
```js
1319
import Swal from 'sweetalert2'
1420

1521
window.Swal = Swal
1622
```
1723

18-
3. Include the SweetAlert2 template in your layout file (usually `resources/views/layouts/app.blade.php`):
24+
4. Include the SweetAlert2 template in your layout file (usually `resources/views/layouts/app.blade.php`):
1925

2026
```blade
21-
@if (session()->has('sweetalert2'))
22-
<script type="module">
23-
Swal.fire(@json(session('sweetalert2')))
24-
</script>
25-
@endif
27+
@include('vendor.sweetalert2.index')
2628
```
2729

2830
## Usage
@@ -44,9 +46,11 @@ The full list of options can be found in the [SweetAlert2 documentation](https:/
4446
4547
## FAQ
4648
47-
### 1. What's the difference with https://github.com/realrashid/sweet-alert package?
49+
### 1. What's the difference with [realrashid/sweet-alert](https://github.com/realrashid/sweet-alert) package?
50+
51+
The `realrashid/sweet-alert` package is too opinionated and too complex: facade, midddleware, whatnot 🤯. And all that with 0 tests.
4852

49-
The `realrashid/sweet-alert` package is too opinionated and too complex (facade, midddleware, whatnot 🤯). This package is simple, straightforward, and unopinionated. It's API is aimed to be as close as possible to the original [sweetalert2](https://sweetalert2.github.io/#configuration).
53+
This package is simple, straightforward, and unopinionated. It's API is aimed to be as close as possible to the original [sweetalert2](https://sweetalert2.github.io/#configuration).
5054
5155
It simply provides a way to use SweetAlert2 in your Laravel application without touching JS or CSS files.
5256

composer.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,12 @@
99
"psr-4": {
1010
"SweetAlert2\\Laravel\\": "src/"
1111
}
12+
},
13+
"extra": {
14+
"laravel": {
15+
"providers": [
16+
"SweetAlert2\\Laravel\\ServiceProvider"
17+
]
18+
}
1219
}
1320
}

resources/views/index.blade.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@if (session()->has('sweetalert2'))
2+
<script type="module">
3+
Swal.fire(@json(session('sweetalert2')))
4+
</script>
5+
@endif

resources/views/sweetalert2.blade.php

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/ServiceProvider.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace SweetAlert2\Laravel;
4+
5+
class ServiceProvider extends \Illuminate\Support\ServiceProvider
6+
{
7+
/**
8+
* Copy the package vendor files.
9+
*/
10+
public function boot(): void
11+
{
12+
$this->publishes([
13+
__DIR__.'/../resources/views' => resource_path('views/vendor/sweetalert2'),
14+
], 'sweetalert2');
15+
}
16+
}

0 commit comments

Comments
 (0)