Confirmation before deleting an item

Submitted by ismaeltoe - 1 year 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>
comments powered by Disqus

Ads cover the costs of maintaining Laravel-tricks