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 the weekly newsletter and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Full-Stack Developer
Tampa, FL / Remote
Nu Image Medical
PHP Developer
Remote
X-Team
Full-Stack Developer
Sioux Falls, SD or Remote
Electric Pulp
Senior PHP / Vue.js Developer
Portland, OR / Remote
Bright Oak
Full Stack Vue.js Developer (Front-end focus)
Remote
LenderHomePage.com
Senior Laravel Web Application Developer
NYC or Remote
Happy Cog
Laravel Developer (Vue, SQL Server)
Geneva, Switzerland / Remote
World Trade Organization