Delete record using ajax request in Laravel Example (ok)

https://www.itsolutionstuff.com/post/delete-record-using-ajax-request-in-laravel-exampleexample.html

C:\xampp\htdocs\reset\routes\web.php

<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\UserController;
/*
|--------------------------------------------------------------------------
| 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('users/{id}', [UserController::class, 'destroy'])->name('users.destroy');

C:\xampp\htdocs\reset\app\Http\Controllers\UserController.php

Delete record using ajax request in Laravel Example

By Hardik Savani December 27, 2018 Category : PHP Laravel jQuery AjaxPlayUnmuteLoaded: 0.69%FullscreenVDO.AI

A very few days ago, i was trying to delete record using jquery ajax request in my laravel 5.7 app. i always make delete record using jquery ajax, so i also want to delete record with ajax request in laravel 5, laravel 6, laravel 7, laravel 8 and laravel 9.

we will create delete route with controller method(we will write delete row code using database model) and write jquery ajax code with delete post request. we also pass csrf token in jquery ajax request, otherwise it will return error like delete method not allowed.

you have to simply follow few things to make done delete record from database using ajax request. Let's follow few steps.

Create Route: routes/web.php

Controller Method: app/Http/Controllers/UserController.php

View Code: resources/views/users.php

JS Code: resources/views/users.php

Read Also: Laravel 5.7 Import Export Excel to database Example

Now you can check it.

I hope it can help you...

Last updated

Was this helpful?