Laravel Sweet Alert Tutorial Example




Laravel Sweet Alert Tutorial Example

Hi Guys

Now, let's see post of laravel sweetalert example tutorial. you'll learn laravel sweet alert box using data delete. if you have question about laravel sweetalert then i will give simple example with solution. This post will give you simple example of sweet alert for laravel example. you will do the following things for laravel sweetalert using record delete.

In this example,we will learn how to open sweetalert before deleting user in laravel application. I will show sweetalert jquery plugin using delete in laravel.I will show easy example of sweet alert before deleting user in laravel.

Sweetalert.js provide us very simple it's simply use event of their plugin. So let's see bellow full example and you can implement sweet alert model before delete record in your web application.

We will sweetalert before deleting user in laravel. so in this example we will using "users" table using laravel migration and write code for route, controller and view step by step.

Here the example of sweetalert before deleting user in laravel.

Step 1 : Install Laravel App

In this step, You can install laravel fresh app. So open terminal and put the bellow command.

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

Step 2 : Setup Database Configuration

After successfully install laravel app thenafter configure databse setup. We will open ".env" file and change the database name, username and password in the env file.







Step 3: Add New Route

In this step, we are doing from scratch so we will add two routes, one for display data and another for delete request. So you have to simply add two new routes in your laravel application.


Route::get('users', 'UserController@index');


Step 4: Create UserController

In third step, we will create new UserController file to handle request of created two new route. In this Controller we define two method, index() and destroy(). Both method will handle route request. So let's create new controller and put code:

php artisan make:controller UserController

After successfully run above command . So, let's copy bellow code and put on UserController.php file.



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\User;

class UserController extends Controller


public function index()


$users = User::get();

return view('user',compact('users'));


public function destroy(Request $request,$id)



return back();



Step 5: Create user blade file

In last step we will create user.blade.php file and write code of display user detail and sweet alert code.


<!DOCTYPE html>



<title>Laravel Sweet Alert Tutorial Example -</title>

<link rel="stylesheet" type="text/css" href="">

<script src=""></script>

<link rel="stylesheet" href="" />

<script src=""></script>

<meta name="csrf-token" content="{{ csrf_token() }}">


<body class="bg-dark">

<div class="container">

<div class="row">

<div class="col-md-8 offset-md-2">

<div class="card mt-5">

<div class="card-header">

<h5>Laravel Sweet Alert Tutorial Example -</h5>


<div class="card-body">

<table class="table table-bordered">



<td>Email& lt;/td>

<td width="5%">Action</td>


@foreach($users as $user)


<td>{{ $user->name }}</td>

<td>{{ $user->email }}</td>


<button class="btn btn-danger btn-flat btn-sm remove-user" data-id="{{ $user->id }}" data-action="{{ route('users.destroy',$user->id) }}"> Delete</button>










<script type="text/javascript">


var current_object = $(this);


title: "Are you sure?",

text: "You will not be able to recover this imaginary file!",

type: "error",

showCancelButton: true,

dangerMode: true,

cancelButtonClass: '#DD6B55',

confirmButtonColor: '#dc3545',

confirmButtonText: 'Delete!',

},function (result) {

if (result) {

var action = current_object.attr('data-action');

var token = jQuery('meta[name="csrf-token"]').attr('content');

var id = current_object.attr('data-id');

$('body').html("<form class='form-inline remove-form' method='post' action='"+action+"'></form>");

$('body').find('.remove-form').append('<input name="_method" type="hidden" value="delete">');

$('body').find('.remove-form').append('<input name="_token" type="hidden" value="'+token+'">');

$('body').find('.remove-form').append('<input name="id" type="hidden" value="'+id+'">');








Now we are ready to run our example so run bellow command for quick run:

php artisan serve

Now you can open bellow URL on your browser:


It will help you...

#Laravel 7


#Laravel 6