How to Show Sweet Alert Delete Confirmation in Laravel | Laravel E-Commerce Project Tutorial

Поділитися
Вставка
  • Опубліковано 9 лис 2024

КОМЕНТАРІ • 16

  • @ivangerginov5648
    @ivangerginov5648 6 місяців тому

    Thanks! Informative and well explained

  • @Ithicuss
    @Ithicuss 5 місяців тому +1

    Nice course so far. Really helpful. This is the first proper laravel 11 course I've come acress so far. One suggestion would be to use a form to make a delete request, rather than a simple anchor link. This I think is more in line with laravel best practices. Another suggestion would be to use an event listener rather than an onclick event for each button.
    I wrote some code for this, maybe someone finds this helpful. -- it works on my end :p --
    Foreach for each button:
    @foreach ($categories as $category)
    {{ $category->category_name }}

    @csrf
    @method('DELETE')


    @endforeach
    The JS:
    document.querySelectorAll('.deleteBtn').forEach(form => {
    form.addEventListener('submit', function(event) {
    event.preventDefault(); // Prevent the default form submission}
    let urlToRedirect = event.currentTarget.getAttribute('action')
    let category = event.currentTarget.dataset.name;
    swal({
    title: `Do you want to delete the Category \"${category}\"?`,
    text: "This cannot be undone",
    icon: 'warning',
    buttons: true,
    dangerMode: true,
    })
    .then((willCancel) => {
    if (willCancel) {
    // window.location.href=urlToRedirect;
    form.submit();
    }
    });
    });
    })

  • @Struggling.to.be_momin
    @Struggling.to.be_momin 3 місяці тому

    Thanks sir

  • @thiobakti2159
    @thiobakti2159 2 місяці тому

    Thank you

  • @JayantKumar4204
    @JayantKumar4204 3 місяці тому

    i have gone through all the process from toastr to sweetalert in the same way as you said in the video but still my data is being deleted by just clicking the delete button and the toastr alert is there. kindly help.

  • @hounglymeng
    @hounglymeng 6 місяців тому

    Great man!

  • @HamdanHamdan-g6t
    @HamdanHamdan-g6t 29 днів тому

    It's not working for me

  • @abdullahabusyeed7032
    @abdullahabusyeed7032 2 місяці тому

    Instead of willCancel now have to use will Delete...otherwise not working

  • @VikneshSekaran
    @VikneshSekaran 4 місяці тому

    Cancel not working sir comment run but call ok select but cancel not working

  • @Royalplz
    @Royalplz 3 місяці тому

    plz help onclick button function not working did code updated plz give reliable solution

  • @lambangyanuar2586
    @lambangyanuar2586 3 місяці тому

    hello, I have followed everything in the video but it doesn't appear as shown in the video, please help

    • @archer5164
      @archer5164 3 місяці тому

      @@lambangyanuar2586 Try changing console.Log into console.log

    • @egamomusu
      @egamomusu 3 місяці тому

      it happened to me too..the delete confirmation pop-up doesn't appear..please help

    • @egamomusu
      @egamomusu 3 місяці тому

      I have resolved the issue. In line 138 and 140 as shown in the video, changed "willCancel" with "willDelete"

    • @lambangyanuar2586
      @lambangyanuar2586 3 місяці тому

      @@egamomusu thanks

    • @Royalplz
      @Royalplz 3 місяці тому

      @@egamomusu not working by doing this also