Laravel Sweet Alert Tutorial With Example

Laravel Sweet Alert Tutorial With Example is today’s leading topic. In this example, we will learn how to use sweet alert in laravel 5.6. Sweetalert is a Plugin which will make popup messages easy and pretty. We use uxweb/sweet-alert package. You can also use the sweet alert for confirmation before save or delete. We can also implement sweet alert instead of bootstrap confirmation. There are the different type of alert like a message, basic, info,success, error, warning.

Laravel Sweet Alert Tutorial With Example

We are going to Configure Laravel Project.

#1: Install Laravel Project

Install Laravel 5.6 Project by the typing following command.

composer create-project --prefer-dist laravel/laravel sweetalertexample

#2: Install sweet alert package

Next, we will install the sweet alert package through composer.

composer require uxweb/sweet-alert

As i install Laravel 5.6 so I don’t need to add Anything in providers and alias array within config/app.php

If you are using Laravel 5.4 or less version then you, include the service provider within config/app.php

'providers' => [

And, add a facade alias to this same file at the bottom.

‘aliases’ => [
               ‘Alert’ => UxWeb\SweetAlert\SweetAlert::class,

#3: Create one controller

php artisan make:controller SweetalertController

It will build the controller file called SweetalertController.php.



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Alert;

class SweetalertController extends Controller
    public function notification($type)
        switch ($type) {
            case 'message':
                Alert::message('Hello Investmentnovel','Message');
            case 'basic':
                Alert::basic('Welcome Investmentnovel','Basic');
            case 'info':
                Alert::info('Mail Sent','Info');
            case 'success':
                Alert::success('Your message has been successfully sent', 'Success');
            case 'error':
                Alert::error('Something went wrong','Error');
            case 'warning':
                Alert::warning('Please activate your account','Warning');
        return view('sweetalert');

#4: Define Route

We register all route in a web.php file.



#5: Create a View File

You can create a file in resources/views/sweetalert.blade.php and put this following code in it.

<!-- sweetalert.blade.php -->

<!DOCTYPE html>
    <meta charset="utf-8">
    <title>Laravel Sweet Alert Tutorial With Example </title>
	<link rel="stylesheet" href="" />
	<script src=""></script>
    <h2>Laravel Sweet Alert Tutorial With Example</h2>

Run the project by typing following command.

php artisan serve

Now we can see the output in the below screenshot.

  1. Message:

Laravel Sweet Alert Example

2. Basic

Laravel Sweet Alert Tutorial

3. Info

Sweet Alert In Laravel Example

4. Success

How to implement sweet alert in laravel

5. Error

How to use sweet alert in laravel example

6. Warning

Laravel Sweet Alert Tutorial With Example

At last, our Laravel Sweet Alert Tutorial With Example is over.

2 thoughts on “Laravel Sweet Alert Tutorial With Example”

  1. hi i have donoe everything ans written in artcle.but ist not working why? i have done everythinhg but result is negative..


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.