Laravel Sweet Alert AJAX CRUD Tutorial

Today, We want to share with you Laravel Sweet Alert AJAX CRUD Tutorial.In this post we will show you Delete method with Sweet Alert in Laravel, hear for How to make a delete confirmation Window with Sweet Alert we will give you demo and example for implement.In this post, we will learn about Confirm Delete Button on CRUD with SweetAlert and LARAVEL 5.7 with an example.

Laravel Sweet Alert AJAX CRUD Tutorial

There are the Following The simple About Laravel Sweet Alert AJAX CRUD Tutorial Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel Sweet Alert Delete confirmation Example, so the Laravel Sweet Alert Tutorial for this example is following below.

Include CDN

A Easy Sweet Alert Messages for Laravel package to show SweetAlerts with the Laravel Framework

<link href="{{ URL::asset('css/sweetalert.css') }}" rel="stylesheet" type="text/css"/>
<script src="{{ URL::asset('js/sweetalert.min.js') }}" type="text/javascript"></script>

Laravel Sweet Alert Delete confirmation Example

JavaScript Source Code

<script>
    $(document).ready(function () {
        $(document).on('click', '.delete', function (e) {
            e.preventDefault();
            var el = this;
            var user_id= $(this).attr("data-id");

                  swal({
                  title: "Do you want to delete this User?",
                  type: "warning",
                  showCancelButton: true,
                  confirmButtonClass: "btn",
                  confirmButtonText: "Confirm",
                  cancelButtonText: "Cancel",
                  closeOnConfirm: false,
                  closeOnCancel: false,
                  timer: 5000
                },
                function(isConfirm) {
                  if (isConfirm) {
                   
                     $.ajaxSetup({
                            headers: {
                                'X-CSRF-TOKEN': '{{csrf_token()}}'
                            }
                        });
                        $.ajax(
                        {
                            url: "users/delete/"+user_id,
                            type: 'delete', // replaced from put
                            dataType: "JSON",
                            data: {
                                "id": user_id // method and token not needed in data
                            },
                            success: function (response)
                            {
                                 // Remove row from HTML Table
                                 $(el).closest('tr').css('background','tomato');
                                 $(el).closest('tr').fadeOut(800,function(){
                                    $(this).remove();
                                 });
                                 swal("Deleted!", response.message, "success");
                            },
                            error: function(xhr) {
                             console.log(xhr.responseText);
                           }
                        });

                  } else {
                    swal("Cancelled", "You Cancelled", "error");
                  }
              });
        });
    });
</script>

Laravel Controller

public function destroy(Request $request)
{
    User::find($request->id)->delete();
    return response()->json(['message'=>"User deleted successfully")]);
}

Laravel sweet alert github

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

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

Related Keywords: :Confirm Delete using Sweetalert, Laravel SweetAlert, Sweet Alert with Laravel 5.7, sweet alert github, sweet alert github, alert box in laravel, laravel galaxy, laravel project examples, laravel 5.7 media manager, Laravel Sweet Alert Delete confirmation Example, Confirm Delete Button on CRUD with SweetAlert and LARAVEL 5.7, How to make a delete confirmation Window with Sweet Alert, Delete method with Sweet Alert in Laravel, Laravel Sweet Alert Delete confirmation Example

I hope you get an idea about Laravel Sweet Alert AJAX CRUD Tutorial.
I would like to have feedback on my Pakainfo.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.   Laravel 6 Global Scope Tutorial Example
  2.   vue Check box binding Example
  3.   Laravel 6 Advanced Where Clauses Tutorial With Example
  4.   jQuery Validate CKEditor value is blank or not
  5.   Laravel 6 drop column if exists MySQL using Migration
  6.   Woocommerce Get product image url from an image_id
  7.   Laravel 6 Sweet Alert Tutorial With Example
  8.   vuejs Dynamic CSS-SCSS Example
  9.   how to clear cache in laravel 5/6/7?
  10.   Get Current login Auth user details using Laravel 5.7