/home/techb158/ileadtechnology.com/vendor/realrashid/sweet-alert/docs
NameSizeModeActions
css/-0755rm
imgs/-0755rm
.nojekyll00644editdlrm
carbonad.js22360644editdlrm
changelog.md39550644editdlrm
config.md6140644editdlrm
credits.md7920644editdlrm
demo.md30410644editdlrm
enterprise.md6060644editdlrm
environment.md65940644editdlrm
helpers.md45920644editdlrm
index.html40720644editdlrm
install.md7040644editdlrm
middleware.md37100644editdlrm
README.md20500644editdlrm
sw.js30920644editdlrm
tutorial.md31160644editdlrm
usage.md16780644editdlrm
_coverpage.md3810644editdlrm
_sidebar.md5440644editdlrm
Edit: /home/techb158/ileadtechnology.com/vendor/realrashid/sweet-alert/docs/middleware.md (3710B)
# Middleware ### Using the Middleware First thing first Let register the middleware in web middleware groups by simply adding the middleware class ```php \RealRashid\SweetAlert\ToSweetAlert::class, ``` into the `$middlewareGroups` of your `app/Http/Kernel.php` file. ### 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 Now within your controllers, just set your return message and send the proper message and proper type. #### Alert Errors Alert ```php public function store(Request $request) { //validation $request->validate([ 'title' => 'required|min:3', 'body' => 'required|min:3' ]); $task = Task::create($request->all()); return redirect('tasks')->with('success', 'Task Created Successfully!'); // OR return redirect('tasks')->withSuccess('Task Created Successfully!'); } ``` Error Alert ```php public function store(Request $request) { $validator = Validator::make($request->all(), [ 'title' => 'required|min:3', 'body' => 'required|min:3' ]); if ($validator->fails()) { return back()->with('errors', $validator->messages()->all()[0])->withInput(); } $task = Task::create($request->all()); return redirect('tasks')->with('success', 'Task Created Successfully!'); // OR return redirect('tasks')->withSuccess('Task Created Successfully!'); } ``` Success Alert ```php public function store(Request $request) { //validation $task = Task::create($request->all()); return redirect('tasks')->with('success', 'Task Created Successfully!'); // OR return redirect('tasks')->withSuccess('Task Created Successfully!'); } ``` ```php return redirect('route')->with('type', 'message'); // OR return redirect('route')->withType('message'); ``` All available types : `error` `success` `info` `warning` `question` . #### Toast Error Toast ```php public function store(Request $request) { $validator = Validator::make($request->all(), [ 'title' => 'required|min:3', 'body' => 'required|min:3' ]); if ($validator->fails()) { return back()->with('toast_error', $validator->messages()->all()[0])->withInput(); } $task = Task::create($request->all()); return redirect('tasks')->with('success', 'Task Created Successfully!'); // OR return redirect('tasks')->withSuccess('Task Created Successfully!'); } ``` Success Toast ```php public function store(Request $request) { $validator = Validator::make($request->all(), [ 'title' => 'required|min:3', 'body' => 'required|min:3' ]); if ($validator->fails()) { return back()->with('toast_error', $validator->messages()->all()[0])->withInput(); } $task = Task::create($request->all()); return redirect('tasks')->with('toast_success', 'Task Created Successfully!'); // OR return redirect('tasks')->withToastSuccess('Task Created Successfully!'); } ``` ```php return redirect('route')->with('toast_type', 'message'); // OR return redirect('route')->withToastType('message'); ``` All available types `toast_error` `toast_success` `toast_info` `toast_warning` `toast_question`. !> You can not use helper methods with Middleware but you can set default values in `config/sweetalert.php` file! **Recommend** to use the .env keys. ``` SWEET_ALERT_MIDDLEWARE_AUTO_CLOSE=false SWEET_ALERT_MIDDLEWARE_TOAST_POSITION='top-end' SWEET_ALERT_MIDDLEWARE_TOAST_CLOSE_BUTTON=true SWEET_ALERT_MIDDLEWARE_ALERT_CLOSE_TIME=5000 SWEET_ALERT_AUTO_DISPLAY_ERROR_MESSAGES=true ``` > Positions **'top'**, **'top-start'**, **'top-end'**, > **'center'**, **'center-start'**, **'center-end'**, **'bottom'**, **'bottom-start'**, or **'bottom-end'**.