Laravel - Confirmation Before Delete Record from Database Example (ok)
https://www.itsolutionstuff.com/post/laravel-5-confirmation-before-delete-record-from-database-exampleexample.html
C:\xampp\htdocs\reset\routes\web.php
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\ProductController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', [HomeController::class, 'index'])->name('home');
Route::get('myproducts', [ProductController::class, 'index']);
Route::delete('myproducts/{id}', [ProductController::class, 'destroy']);C:\xampp\htdocs\reset\database\migrations\2022_05_20_161330_create_products_table.php
C:\xampp\htdocs\reset\app\Http\Controllers\ProductController.php
C:\xampp\htdocs\reset\resources\views\products.blade.php

Laravel - Confirmation Before Delete Record from Database Example
By Hardik Savani June 29, 2017 Category : PHP Laravel Bootstrap jQuery MySql AjaxPlayUnmuteLoaded: 1.15%Fullscreen
Hi Guys, In this post we will learn how to open confirm model box before deleting item in laravel 5 application. As we know very well delete operation is very command and basic feature of every web application. Also delete operation is very important part because if you remove item, post, product, category etc then it will remove from your browser. So we should always prefer to confirmation before remove item in laravel 6, laravel 7, laravel 8 and laravel 9 app.
There are several options available to use confirm like jquery ui confirm, sweetalert, bootbox, bootstrap confirmation etc jquery plugin. So we almost use bootstrap theme so it would always better if we use bootstrap plugin for this task. So In this example i am going to use bootstrap confirmation plugin for confirm box like toggle.
bootstrap-confirmation.js provide us very simple and better layout for confirm box and it's simply use event of their plugin. So let's see bellow full example and you can implement confirmation before delete record in your web application. you will get layout like as bellow screen shot.
Layout:

Step 1: Add Table and Dummy Records
I always prefer to give example from scratch, So in this example we will create "products" table with id, name, details, created_at and updated_at column. So you have to create table using migration and run that. After created successfully create table, make sure add some dummy data like as bellow:
Products Insert Query:
Step 2: 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.
routes/web.php
Read Also: Laravel 5 Autocomplete using Bootstrap Typeahead JS Example with Demo
Step 3: Create ProductController
In third step, we will create new ProductController 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:
app/Http/Controllers/ProductController.php
Step 4: Create products blade file
In last step we will create products.blade.php file and write code of display products and jquery ajax code. In this file we added following css and js files:
1)bootstrap.min.css
2)bootstrap.min.js
3)jquery.min.js
4)bootstrap-confirmation.min.js
So, let's create products.blade.php file and put bellow code:
resources/views/products.blade.php
Read Also: jQuery Ajax X-editable bootstrap plugin to update records in PHP Example
Ok, now we are ready to run above example with great layout. So let's run on following url: Site_URL+'/myproducts'.
I hope it can help you....
Last updated
Was this helpful?