Php how to delete multiple rows through checkbox using ajax in laravel

Php how to delete multiple rows through checkbox using ajax in laravel

In this article i will let you know to delete multiple rows through checkbox using ajax in laravel and before delete we will give a confirmation message.

First thing, we will need a table and i am creating products table for this example. So run the following query to create table.

CREATE TABLE `products` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
 `description` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
 `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
 `updated_at` datetime DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

Next, we will need to insert some dummy records in this table that will be deleted.

INSERT INTO `products` (`name`, `description`) VALUES

('Test product 1', 'Product description example1'),

('Test product 2', 'Product description example2'),

('Test product 3', 'Product description example3'),

('Test product 4', 'Product description example4'),

('Test product 5', 'Product description example5');

Now we are redy to create a model corresponding to this products table. Here we will create Product model. So let’s create a model file Product.php file under app directory and put the code below.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $fillable = [
        'name','description'
    ];
}

Step 2: Create Route

Now, in this second step we will create some routes to handle the request for this example. So opeen routes/web.php file and copy the routes as given below.

routes/web.php

Route::get('product', '[email protected]');
Route::delete('product/{id}', ['as'=>'product.destroy','uses'=>'[email protected]']);
Route::delete('delete-multiple-product', ['as'=>'product.multiple-delete','uses'=>'[email protected]']);

laravel delete multiple rows in laravel using ajax laravel ajax delete laravel ajax multiple checkbox delete laravel delete multiple rows laravel delete records using ajax laravel multiple checkbox delete rows laravel multiple delete

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Ajax Multiple Image Upload with Progress bar with jQuery in Laravel

Laravel multiple file upload with progress bar ajax. Here, we will show you how to upload multiple file with progress bar using ajax in laravel

Country State City Drop Down List using Ajax in Laravel

Laravel ajax country state city dropdown. Here, we will show you how to create laravel dependent country state city dropdown with ajax & demo

Laravel 7.x/6 Multiple Image Upload Ajax

laravel 7 ajax multiple image upload with preview example. Here you will learn how to upload multiple images using ajax with preview in laravel apps.

Laravel 7 Multiple Image Upload with Preview

laravel 7 ajax multiple image upload with preview example. Here you will learn how to upload multiple images using ajax with preview in laravel apps.

Multiple File Upload in Laravel 7, 6

laravel 7.x,6 multiple file upload with validation example. This tutorial explains, how you can upload multiple files into laravel folder and MySQL DB