It’s always better to ask for the confirmation while deleting items with alert prompt. So here I am gonna show you, how to show the confirmation prompt with Javascript within your Laravel application.
HTML for delete button
If you seen below code, $items is iterable object, its generating likes for all the available items.
1 2 3 4 5 6 7 |
@foreach ($items as $item) <form class="delete" action="{{ route('item.destroy', $item->id) }}" method="POST"> <input type="hidden" name="_method" value="DELETE"> <input type="hidden" name="_token" value="{{ csrf_token() }}" /> <input type="submit" value="Delete"> </form> @endforeach |
Javascript to show the confirm prompt
Place below javaScript in your page footer area.
1 2 3 4 5 |
<script> $(".delete").on("submit", function(){ return confirm("Do you want to delete this item?"); }); </script> |
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.
Subscribe
Login
0 Comments