Laravel Delete Record using jquery Ajax Request

Rate this post

Today, We want to share with you Laravel Delete Record using jquery Ajax Request.In this post we will show you Delete record using ajax request in Laravel Example, hear for laravel ajax delete method not allowed we will give you demo and example for implement.In this post, we will learn about Delete Record using Ajax Request in Laravel with an example.

Laravel Delete Record using jquery Ajax Request

There are the Following The simple About Insert Update and Delete record with AJAX in Laravel Full Information With Example and source code.

As I will cover this Post with live Working example to develop Delete a record from table using ajax in laravel 6, so the How to Delete or Remove Mysql Data in Laravel using Ajax is used for this example is following below.

Read Also:  PHP Laravel Eloquent Increments and Decrements value

Delete Record using ajax call with laravel 6

routes/web.php

Route::delete('/addmovie/{id}', '[email protected]')->name('movie.destroy');

app/Http/Controllers/MovieController.php

public function destroy($id){
   
      $movie = Movie::find($id);
      $movie->delete();
      return response()->json([
        'message' => 'Movie deleted successfully!'
      ]);

}

resources/views/movie.blade.php

//sweet alert cdn
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>

 <a href="{{ route('movie.destroy',$element->id) }}" class="btn btn-sm btn-outline-danger py-0" style="font-size: 0.8em;" id="deleteMovie" data-id="{{ $element->id }}">
   Delete
</a>

resources/views/movie.blade.php

$(document).ready(function () {

    $("#deleteMovie").click(function(e){

    if(!confirm("Do you really want to do this Movie?")) {
       return false;
     }

    e.preventDefault();
    var id = $(this).data("id");
    // var id = $(this).attr('data-id');
    var token = $("meta[name='csrf-token']").attr("content");
    var url = e.target;

    $.ajax(
        {
          url: url.href, //or you can use url: "movie/"+id,
          type: 'DELETE',
          data: {
            _token: token,
                id: id
        },
        success: function (response){

            $("#success").html(response.message)

            Swal.fire(
              'Remind!',
              'Movie deleted successfully!',
              'success'
            )
        }
     });
      return false;
   });
    

});

Free Live Chat for Any Issue
Web Programming Tutorials Example with Demo

Read :

Read Also:  many to many relationship sql - How to Create a Many-to-Many Relationship?

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

Download

I hope you get an idea about datatable delete row in laravel.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.