├── README.md
├── composer.json
└── src
├── Facades
└── Toastr.php
├── Toastr.php
├── ToastrServiceProvider.php
├── config
└── toastr.php
└── helper.php
/README.md:
--------------------------------------------------------------------------------
1 | Inspired in whossun/laravel-toastr..
2 |
3 | I cloned the repository brian2694/laravel-toastr to update to Laravel 5.5
4 |
5 | # laravel-toastr
6 |
7 | | Laravel Version | Is Working? |
8 | | --- | --- |
9 | | 10.x | Yes |
10 | | 9.x | Yes |
11 | | 8.x | Yes |
12 | | 7.x | Yes |
13 | | 6.x | Yes |
14 | | >= 5.5 | Yes |
15 | | <= 5.4 | Yes |
16 |
17 |
18 | ### install
19 |
20 | Using Composer
21 |
22 | composer require brian2694/laravel-toastr
23 |
24 | ### Laravel >= 5.5
25 |
26 | That's it! The package is auto-discovered on 5.5 and up!
27 |
28 | ### Laravel <= 5.4
29 |
30 | Add the service provider to `config/app.php`
31 |
32 | ```php
33 | Brian2694\Toastr\ToastrServiceProvider::class,
34 | ```
35 |
36 | Optionally include the Facade in config/app.php if you'd like.
37 |
38 | ```php
39 | 'Toastr' => Brian2694\Toastr\Facades\Toastr::class,
40 | ```
41 |
42 |
43 | ### Options
44 |
45 | You can set custom options for Reminder. Run:
46 |
47 | php artisan vendor:publish
48 |
49 | to publish the config file for toastr.
50 |
51 | You can see [toastr's documentation](http://codeseven.github.io/toastr/demo.html) to custom your need.
52 |
53 |
54 | > You can use toastr() function available.
55 |
56 | ### Dependencies
57 |
58 | jQuery [toast](https://github.com/CodeSeven/toastr), you need to add css and js to your html.
59 |
60 | ### Basic
61 |
62 |
63 | * Toastr::info('message', 'title', ['options']);
64 |
65 | * Toastr::success('message', 'title', ['options']);
66 |
67 | * Toastr::warning('message', 'title', ['options']);
68 |
69 | * Toastr::error('message', 'title', ['options']);
70 |
71 | * Toastr::clear();
72 |
73 | * Toastr()->info('message', 'title', ['options']);
74 |
75 | ```php
76 | "toast-top-center"]);
80 |
81 | return view('welcome');
82 | });
83 | ```
84 |
85 | Then
86 |
87 | You should add `{!! Toastr::message() !!}` to your html.
88 |
89 | ```html
90 |
91 |
92 |
93 | Laravel
94 |
95 |
96 |
97 |
102 |
103 |
104 | {!! Toastr::message() !!}
105 |
106 |
107 | ```
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 |
130 |
131 |
132 | ## Contributors
133 |
134 | We'd like to thank the following individuals for their contributions to this project:
135 |
136 | - [Antonio Bruno](https://github.com/antonio8101) - Set DOC on the Facade class.
137 | - [aoradev44](https://github.com/aoradev44) - Set toastr message script type to module for using with vite
138 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "brian2694/laravel-toastr",
3 |
4 | "description": "toastr.js for Laravel",
5 | "keywords": ["toastr", "notification", "laravel", "php"],
6 | "homepage": "https://github.com/brian2694/laravel-toastr",
7 | "license": "MIT",
8 | "authors": [
9 | {
10 | "name": "brian2694",
11 | "email": "briansanchez2694@gmail.com"
12 | }
13 | ],
14 | "autoload": {
15 | "psr-4": {
16 | "Brian2694\\Toastr\\": "src/"
17 | },
18 | "files": [
19 | "src/helper.php"
20 | ]
21 | },
22 | "extra": {
23 | "laravel": {
24 | "providers": [
25 | "Brian2694\\Toastr\\ToastrServiceProvider"
26 | ],
27 | "aliases": {
28 | "Toastr": "Brian2694\\Toastr\\Facades\\Toastr"
29 | }
30 | }
31 | },
32 | "minimum-stability": "dev",
33 | "require": {
34 | "php": ">=5.5.0",
35 | "illuminate/support": ">=5.2.7",
36 | "illuminate/session": ">=5.2.7"
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Facades/Toastr.php:
--------------------------------------------------------------------------------
1 | session = $session;
41 | $this->config = $config;
42 | }
43 |
44 | public function message()
45 | {
46 | $messages = $this->session->get('toastr::messages');
47 |
48 | if (! $messages) $messages = [];
49 |
50 | $script = '';
74 | return $script;
75 | }
76 |
77 | /**
78 | *
79 | * Add a flash message to session.
80 | *
81 | * @param string $type Must be one of info, success, warning, error.
82 | * @param string $message The flash message content.
83 | * @param string $title The flash message title.
84 | * @param array $options The custom options.
85 | *
86 | * @return void
87 | */
88 | public function add($type, $message, $title = null, $options = [])
89 | {
90 | $types = ['error', 'info', 'success', 'warning'];
91 |
92 | if (! in_array($type, $types)) {
93 | throw new Exception("The $type remind message is not valid.");
94 | }
95 |
96 | $this->messages[] = [
97 | 'type' => $type,
98 | 'title' => $title,
99 | 'message' => $message,
100 | 'options' => $options,
101 | ];
102 |
103 | $this->session->flash('toastr::messages', $this->messages);
104 | }
105 |
106 | /**
107 | * Add an info flash message to session.
108 | *
109 | * @param string $message The flash message content.
110 | * @param string $title The flash message title.
111 | * @param array $options The custom options.
112 | *
113 | * @return void
114 | */
115 | public function info($message, $title = null, $options = [])
116 | {
117 | if($message instanceof MessageBag)
118 | {
119 | $messageString = "";
120 | foreach ($message->getMessages() as $messageArray)
121 | {
122 | foreach ($messageArray as $currentMessage)
123 | $messageString .= $currentMessage."
";
124 | }
125 |
126 | $this->add('info', rtrim($messageString, "
"), $title, $options);
127 | }
128 | else
129 | $this->add('info', $message, $title, $options);
130 | }
131 |
132 | /**
133 | * Add a success flash message to session.
134 | *
135 | * @param string $message The flash message content.
136 | * @param string $title The flash message title.
137 | * @param array $options The custom options.
138 | *
139 | * @return void
140 | */
141 | public function success($message, $title = null, $options = [])
142 | {
143 | if($message instanceof MessageBag)
144 | {
145 | $messageString = "";
146 | foreach ($message->getMessages() as $messageArray)
147 | {
148 | foreach ($messageArray as $currentMessage)
149 | $messageString .= $currentMessage."
";
150 | }
151 |
152 | $this->add('success', rtrim($messageString, "
"), $title, $options);
153 | }
154 | else
155 | $this->add('success', $message, $title, $options);
156 | }
157 |
158 | /**
159 | * Add an warning flash message to session.
160 | *
161 | * @param string $message The flash message content.
162 | * @param string $title The flash message title.
163 | * @param array $options The custom options.
164 | *
165 | * @return void
166 | */
167 | public function warning($message, $title = null, $options = [])
168 | {
169 | if($message instanceof MessageBag)
170 | {
171 | $messageString = "";
172 | foreach ($message->getMessages() as $messageArray)
173 | {
174 | foreach ($messageArray as $currentMessage)
175 | $messageString .= $currentMessage."
";
176 | }
177 |
178 | $this->add('warning', rtrim($messageString, "
"), $title, $options);
179 | }
180 | else
181 | $this->add('warning', $message, $title, $options);
182 | }
183 |
184 | /**
185 | * Add an error flash message to session.
186 | *
187 | * @param string $message The flash message content.
188 | * @param string $title The flash message title.
189 | * @param array $options The custom options.
190 | *
191 | * @return void
192 | */
193 | public function error($message, $title = null, $options = [])
194 | {
195 | if($message instanceof MessageBag)
196 | {
197 | $messageString = "";
198 | foreach ($message->getMessages() as $messageArray)
199 | {
200 | foreach ($messageArray as $currentMessage)
201 | $messageString .= $currentMessage."
";
202 | }
203 |
204 | $this->add('error', rtrim($messageString, "
"), $title, $options);
205 | }
206 | else
207 | $this->add('error', $message, $title, $options);
208 | }
209 |
210 | /**
211 | * Clear messages
212 | *
213 | * @return void
214 | */
215 | public function clear()
216 | {
217 | $this->messages = [];
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 | }
227 | }
228 |
--------------------------------------------------------------------------------
/src/ToastrServiceProvider.php:
--------------------------------------------------------------------------------
1 | publishes([
16 | __DIR__ . '/config/toastr.php' => config_path('toastr.php'),
17 | ], 'config');
18 | }
19 |
20 | /**
21 | * Register the application services.
22 | *
23 | * @return void
24 | */
25 | public function register()
26 | {
27 | $this->app->singleton('toastr', function ($app) {
28 | return new Toastr($app['session'], $app['config']);
29 | });
30 | }
31 |
32 | /**
33 | * Get the services provider by the provider
34 | *
35 | * @return array
36 | */
37 | public function provides()
38 | {
39 | return ['toastr'];
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/config/toastr.php:
--------------------------------------------------------------------------------
1 | [
5 | "closeButton" => false,
6 | "debug" => false,
7 | "newestOnTop" => false,
8 | "progressBar" => false,
9 | "positionClass" => "toast-top-right",
10 | "preventDuplicates" => false,
11 | "onclick" => null,
12 | "showDuration" => "300",
13 | "hideDuration" => "1000",
14 | "timeOut" => "5000",
15 | "extendedTimeOut" => "1000",
16 | "showEasing" => "swing",
17 | "hideEasing" => "linear",
18 | "showMethod" => "fadeIn",
19 | "hideMethod" => "fadeOut"
20 | ],
21 | ];
22 |
--------------------------------------------------------------------------------
/src/helper.php:
--------------------------------------------------------------------------------
1 |