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

Software Engineer Lead (PHP)
Remote
CivicPlus, LLC
Full-time Senior Web Developer
Detroit, MI
Wayne State University
Senior Software Engineer
Sydney, Australia
FoodByUs
Full Stack Engineer
Remote or Medford, Oregon
Empire Medical
Laravel Developer (fulltime - Dutch only)
Netherlands
Qbixx | Webservices
Full Stack or Back-End Developer
Alexandria, VA; Tallahassee, FL; Orlando, FL
Marketing for Change
Senior Quality Assurance Engineer
Remote
Bisnow Media