Skip to content

Commit a4b6018

Browse files
authored
Merge pull request #16 from aoradev44/master
Set toastr message script type to module for using with vite
2 parents 6c7d1c6 + 27409bc commit a4b6018

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,27 @@ You should add `{!! Toastr::message() !!}` to your html.
106106
</html>
107107
```
108108

109+
### Use ViteJs / script type defaults to module
110+
111+
You can also set Toastr to use vitejs by default by registering `Toastr::useVite()` inside the `AppServiceProvider`.
112+
113+
```php
114+
namespace App\Providers;
115+
116+
use Illuminate\Support\ServiceProvider;
117+
use Brian2694\Toastr\Facades\Toastr;
118+
119+
class AppServiceProvider extends ServiceProvider
120+
{
121+
public function boot(): void
122+
{
123+
Toastr::useVite();
124+
}
125+
}
126+
```
127+
128+
Upon registering, you can now use `Toastr::message()` and it set the script type to module.
129+
109130

110131

111132
## Contributors

src/Toastr.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ class Toastr
2828
*/
2929
protected $messages = [];
3030

31+
/**
32+
* The js type src type.
33+
*
34+
* @var string
35+
*/
36+
protected $jsType = 'text/javascript';
37+
3138
function __construct(Session $session, Config $config)
3239
{
3340
$this->session = $session;
@@ -40,7 +47,7 @@ public function message()
4047

4148
if (! $messages) $messages = [];
4249

43-
$script = '<script type="text/javascript">';
50+
$script = '<script type="'.$this->jsType.'">';
4451

4552
foreach ($messages as $message) {
4653
$config = (array) $this->config->get('toastr.options');
@@ -209,4 +216,12 @@ public function clear()
209216
{
210217
$this->messages = [];
211218
}
219+
/**
220+
* Set js type to module for using vite
221+
*
222+
* @return void
223+
*/
224+
public function useVite(){
225+
$this->jsType = 'module';
226+
}
212227
}

0 commit comments

Comments
 (0)