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.

Read Also:  Laravel 6 Advanced Where Clauses Tutorial With Example

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

Read Also:  How to use multiple databases in Laravel
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

Read Also:  PHP Creating Unique Title Slugs in Laravel

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. Read Also:  call javascript function from html using onclick
  2. Read Also:  Laravel get multiple checkbox value From View to Controller
  3. Read Also:  Elementor custom taxonomy select
  4. Read Also:  Angularjs Table Pagination Example with Code
  5. Read Also:  laravel order by desc Query Builder
  6. Read Also:  Laravel 6 Sweet Alert Tutorial With Example
  7. Read Also:  Laravel Dynamic Change page Title Tags
  8. Read Also:  Laravel force https with url helper
  9. Read Also:  Laravel 6 Sweet Alert Tutorial With Example
  10. Read Also:  laravel order by desc Query Builder
CLOSEX