How to use alerts in voyager? any example? I want to show alert when post submitting with empty fields.
- Voyager Version: v0.11.14
From a controller you can do something like this:
return redirect('path')->with(['message' => "Your Success Message", 'alert-type' => 'success']);
Or:
return redirect('path')->with(['message' => "Your Error Message", 'alert-type' => 'error']);
Voyager uses toastr Library, and to use it simply you can fire it as an event using following ways :
Toastr::warning($message, $title = null, $options = []) - add a warning toast
Toastr::error($message, $title = null, $options = []) - add an error toast
Toastr::info($message, $title = null, $options = []) - add an info toast
Toastr::success($message, $title = null, $options = []) - add a success toast
Toastr::add($type: warning|error|info|success, $message, $title = null, $options = []) - add a toast
Toastr::clear() - clear all current toasts