Laravel SweetAlert

Laravel SweetAlert

Laravel SweetAlert 2 is a Laravel package by Rashid Ali that integrates the popular JavaScript SweetAlert 2 with Laravel. Using the package’s Alert facade or alert() helper, you can queue up SweetAlert 2 alerts on the frontend from your controller:

use RealRashid\SweetAlert\Facades\Alert;

Alert::success('Success Title', 'Success Message');
Alert::info('Info Title', 'Info Message');
Alert::warning('Warning Title', 'Warning Message');
Alert::error('Error Title', 'Error Message');

// Using the helper
alert()->success('Title','Lorem Lorem Lorem');
alert()->info('Title','Lorem Lorem Lorem');
alert()->warning('Title','Lorem Lorem Lorem');
alert()->error('Title','Lorem Lorem Lorem');

You can also configure the package’s ToSweetAlert middleware to handle SweetAlert 2 messages during a middleware handler:

public function someFunction(Request $request)
{
    return redirect('login')->with('success', 'Login Successfully!');
}

This package provides some of the boilerplate around integrating SweetAlert in an opinionated way. However, you might want to integrate SweetAlert 2 on your own if you need customizations beyond the scope of what this package’s API provides. You should check out the documentation to see what methods are available.

You can learn more about this package and check out the source code on GitHub at realrashid/sweet-alert.

Filed in: News

Newsletter

Join 31,000+ others and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Senior Full Stack PHP Developer (Laravel)
Remote
MAPPEN
Senior Laravel Developer
Remote
ACTO
Senior Full-Stack Engineer
[REMOTE: USA Only]
Curricula
Developers for B2B eCommerce SaaS, AWS serverless, Laravel, Vue, Python
Remote, full time EU only
ES Tech Group
Senior PHP Developer (Laravel)
Remote
The Interaction Design Foundation