Home » Laravel Delete Record using jquery Ajax Request

Laravel Delete Record using jquery Ajax Request

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.

Read Also:  jQuery Ajax Delete Request with Laravel

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.

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;
   });
    

});

Web Programming Tutorials Example with Demo

Read :

Read Also:  laravel 6 Delete Multiple Records Eloquent

Summary

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

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.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  jQuery AJAX laravel 6 Delete Data from database
  2. Read Also:  Bootstrap datepicker Disable Dates Dynamically in jQuery
  3. Read Also:  Codeigniter Fullcalendar Example Tutorial From Scratch
  4. Read Also:  jQuery Capture Webcam Image Using Web Camera in PHP
  5. Read Also:  Laravel Convert object Array JSON String Example
  6. Read Also:  Laravel 6 Install Constant Contact - PHP Examples
  7. Read Also:  Vuejs filterBy orderBy CustomFilter Example
  8. Read Also:  how to insert data using ajax in laravel with datatables?
  9. Read Also:  Update Data in MySQL Using PHP
  10. Read Also:  Wordpress Advanced Search query custom fields

Leave a Comment

Your email address will not be published. Required fields are marked *