How to delete record in Laravel with ajax

Created at 19-Feb-2022 , By samar

How to delete record in Laravel with ajax

We’ll attempt to use programming in this lesson to solve the "How to delete record in Laravel with ajax" puzzle.

You can delete the record in Laravel with ajax. You have to pass the primary id of the record as the route parameter and call the ajax script to delete the record from the table.
  • Delete a record with Ajax using HTML Form in Laravel

    //Web route to delete record from users table
    Route::delete('/user/delete/{id}', 'UserController@delete')->name('user.delete');
    //HTML - Delete user form with ajax script
    <form class="delete-user-form" action="{{ route('user.delete', 1) }}" method="POST">
        {{ csrf_field() }}
        {{ method_field('DELETE') }}
        <button type="submit" class="btn btn-default">Remove</button>
        $(document).on('submit', '.delete-user-form', function(e) {
            var url = $(this).attr('action');
                type: "DELETE",
                url: url,
                    _token: '{{ csrf_token() }}'
                success: function(resp){
            return false;
    //UserController’s delete method
    public function delete($id){
        $resp = array();
            User::where('id', $id)->delete();
            $resp['status'] = true; 
        }catch(\Exception $e){
            $resp['status'] = false;
            $resp['error_msg'] = $e->getMessage();
        return response()->json($resp);

    You can delete record in laravel using ajax. You have to create a web route and add html form with ajax script in blade file. You have to create a delete method in controller and add delete functionality to delete the record from database table.

    Additional Note:

    Add jQuery script in Head or body tag in Laravel blade file.

    <script src="" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="  


Back to code snippet queries related laravel

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.