Confirmation before deleting an item

Submitted by ismaeltoe - 9 years ago

When user clicks on "delete" button, open a confirmation box before deleting an item.

@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

<script>
    $(".delete").on("submit", function(){
        return confirm("Do you want to delete this item?");
    });
</script>