Laravel + jQuery Confirm for Deletion

It’s been one year since my last post. lol, kinda busy with my work. 

Today I will show you how to delete a record using jQuery Confirm.

I’m using Laravel 5.3 for this project.

This will look something like

pretty cool.

First of all you need to know how to set your destroy() function in your controller.

see  Laravel 5 Delete Records in your table, Beginner’s Guide

Second, you need to download or import the jQuery Confirm package in the link above.

Third we need to modify your destroy() function in the controller.

The function should return json() data in order for this to work.

Fourth, depending on your needs, you may change your route, but for this we stick with Route::resource().

Fifth, the blade, in your blade you should add a row ID in your table.

Notice we add dynamic ID in the row, also we added a delete button which value is also correspond the ID of the specific row.

Last step the script

The script will search for the specific row ID in your blade, if it found it, it will send ajax request to the deleteURL. We insert the jQuery Confirm before we trigger the ajax.

Note: make sure you define the scripts in your blade, else it won’t work.

Sharing is caring!