diff --git a/docs/middleware.md b/docs/middleware.md index fbab07e..27d72db 100644 --- a/docs/middleware.md +++ b/docs/middleware.md @@ -1,6 +1,6 @@ # Middleware -#### Using the Middleware +### Using the Middleware First thing first @@ -12,7 +12,11 @@ Let register the middleware in web middleware groups by simply adding the middle into the `$middlewareGroups` of your `app/Http/Kernel.php` file. -> Note: Now all your validation errors will use SweetAlert2! +### Error messages auto displaying + +Set the `SWEET_ALERT_AUTO_DISPLAY_ERROR_MESSAGES` .env value to `true` to activate the automatic displaying for the validation error messages. + +By default, this is not activated. ### Examples diff --git a/src/ToSweetAlert.php b/src/ToSweetAlert.php index bf2cfe5..a99e38e 100644 --- a/src/ToSweetAlert.php +++ b/src/ToSweetAlert.php @@ -36,7 +36,7 @@ public function handle($request, Closure $next) alert()->info($request->session()->get('info')); } - if ($request->session()->has('errors')) { + if ($request->session()->has('errors') && config('sweetalert.middleware.auto_display_error_messages')) { $error = $request->session()->get('errors'); if (!is_string($error)) { diff --git a/src/config/sweetalert.php b/src/config/sweetalert.php index b691a62..92679fa 100644 --- a/src/config/sweetalert.php +++ b/src/config/sweetalert.php @@ -136,6 +136,8 @@ 'toast_close_button' => env('SWEET_ALERT_MIDDLEWARE_TOAST_CLOSE_BUTTON', true), 'alert_auto_close' => env('SWEET_ALERT_MIDDLEWARE_ALERT_AUTO_CLOSE', 5000), + + 'auto_display_error_messages' => env('SWEET_ALERT_AUTO_DISPLAY_ERROR_MESSAGES', false), ], ];