Laravel Delete Record using jquery Ajax Request

Laravel Redirect To Another URL / Web Page - HTTP Laravel Redirects

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.

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:  react onclick open new tab Example Tutorial

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.

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

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