File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -106,6 +106,27 @@ You should add `{!! Toastr::message() !!}` to your html.
106
106
</html >
107
107
```
108
108
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
+
109
130
110
131
111
132
## Contributors
Original file line number Diff line number Diff line change @@ -28,6 +28,13 @@ class Toastr
28
28
*/
29
29
protected $ messages = [];
30
30
31
+ /**
32
+ * The js type src type.
33
+ *
34
+ * @var string
35
+ */
36
+ protected $ jsType = 'text/javascript ' ;
37
+
31
38
function __construct (Session $ session , Config $ config )
32
39
{
33
40
$ this ->session = $ session ;
@@ -40,7 +47,7 @@ public function message()
40
47
41
48
if (! $ messages ) $ messages = [];
42
49
43
- $ script = '<script type="text/javascript "> ' ;
50
+ $ script = '<script type=" ' . $ this -> jsType . ' "> ' ;
44
51
45
52
foreach ($ messages as $ message ) {
46
53
$ config = (array ) $ this ->config ->get ('toastr.options ' );
@@ -209,4 +216,12 @@ public function clear()
209
216
{
210
217
$ this ->messages = [];
211
218
}
219
+ /**
220
+ * Set js type to module for using vite
221
+ *
222
+ * @return void
223
+ */
224
+ public function useVite (){
225
+ $ this ->jsType = 'module ' ;
226
+ }
212
227
}
You can’t perform that action at this time.
0 commit comments