简体   繁体   中英

Laravel: How to use alerts in Voyager admin panel?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM