How to Delete Multiple Records using Checkbox in Laravel?

It’s almost need to give feature for remove multiple records using checkbox, if you are developing e-commerce application or any big web application then you must give feature to delete multiple records.

So in this post, i will let you know how to delete multiple records with checkbox in laravel 5, laravel 6, laravel 7 and laravel 8 application. here i also give multiple delete and you can also delete single records. 

In this example, i simply created “products” table with id, name, details, created_at and updated_at columns. I also added mysql query for add dummy records. Here i use jquery for select all checkboxs and delete all records. So finally you have to follow some step and get the layout like as bellow.

Step 1: Create Project for this command

Step 2 : Go to laravel Project and .env file set msql name

Step 3 :  Create database

Step 4 : Create ProductController for this Command

Step 5 : Create Product migration for this command

Step 5: Product migration add for this Product name and Product details

Step 6: Create products Table for database this command

Step 7: Add ProductController

Here, we will create new ProductController file to handle request of created three new route. In this Controller we define three method, index(), destroy() and deleteAll(). method will handle route request. So let’s create new controller and put code:

app/Http/Controllers/ProductController.php

Step 8: Create new Routes

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

routes/web.php

Step 9 – Set Data in View File in Add Product details

This is the last step in the Laravel 5.8 Crud application, and in this step, we have to set data in the view file which has been store under the resources/views folder because this view file has received data from the controller method, so here we have to set data in the view file. Below you can file all view file which has been used in the Crud application, and you can also find how data have been set and how to make a form in Add Product details

resources/views/sorces.blade.php

Step 10: Add Blade File

In last step, we will create products.blade.php file and write code of jquery for delete and delete all function. So let’s create products.blade.php file and put bellow code:

resources/views/products.blade.php

Step 10: Add Blade File

create() – This method has been used for load the create.blade.php file. In this file, users can find a form for insert new records and filling data insert data requests will be sent to the store() method of CrudsController.php controller class.

resources/views/create.blade.php

Dharmendra K
Latest posts by Dharmendra K (see all)
Total Page Visits: 141 - Today Page Visits: 2