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(); } }); }); })
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.
Thanks! Informative and well explained
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();
}
});
});
})
Thanks sir
Thank you
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.
Great man!
It's not working for me
Instead of willCancel now have to use will Delete...otherwise not working
Cancel not working sir comment run but call ok select but cancel not working
plz help onclick button function not working did code updated plz give reliable solution
hello, I have followed everything in the video but it doesn't appear as shown in the video, please help
@@lambangyanuar2586 Try changing console.Log into console.log
it happened to me too..the delete confirmation pop-up doesn't appear..please help
I have resolved the issue. In line 138 and 140 as shown in the video, changed "willCancel" with "willDelete"
@@egamomusu thanks
@@egamomusu not working by doing this also