MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

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

$ composer create-project --prefer-dist laravel/laravel Multiple_delete "5.8.*"
Code language: JavaScript (javascript)
Terminal running composer create-project to create the Laravel 5.8 Multiple_delete project

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

Laravel .env file with the MySQL database name set in the DB settings

Step 3 :  Create database

Creating the MySQL database for the Laravel Multiple_delete project

Step 4 : Create ProductController for this Command

$ php artisan make:controller Product
Terminal running php artisan make:controller Product to create the Product controller

Step 5 : Create Product migration for this command

$ php artisan make:migration create_product_table
Terminal running php artisan make:migration create_product_table

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

Laravel product migration file with columns added for product name and product details

Step 6: Create products Table for database this command

$ php artisan migrate
Terminal running php artisan migrate to create the products table in the Laravel database

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

Laravel routes/web.php with three product routes for listing, deleting and deleting all selected records

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

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

How to merge two or multiple tables to each other in the Laravel PHP Framework? (Part-3)

Part-1 Part-2 Now, we’ll create the 2nd table State to merge with the Country table. Step 1. Create child file resources/views/State folder with name create.blade.php. Step 2. Create edit.blade.php file. In this…

Read More

How to Display Recent and popular data from Database using left join and OderBy

Fist Step In Welcome.blade.php file for Table Secound Step In Pages.blade.php Third Step In Routing, Go To web.php Forth Step In GestController.php This is Return $gallery View…

Read More

Basic Things To Find Error In Laravel

To be master in finding error and build logic to make query, certain things should understand properly (i) check wheather your routing working properly or controller working…

Read More

CRUD Operations in Laravel PHP Framework

Step 1 – Download Laravel 5.8 In first step you have to download Laravel 5.8 version. For this you have to go to command prompt, in which…

Read More

How to merge two or multiple tables to each other in the Laravel PHP Framework? (Part-2)

How to merge two or multiple tables to each other in the Laravel PHP Framework? Part-1 Part-3 Step 1. Go to app/Country.php. Now, we need to list…

Read More

How to Use Search Functionality with Pagination in Laravel PHP Framework? Part 1

How to use Search Functionality with Pagination in Laravel PHP Framework? We are going to use Search Functionality with Pagination within the CRUD table. Click for the…

Read More