Posted by Arjun on Saturday 3rd June 2017

How to show confirmation prompt while deleting row in Laravel.

How to Laravel 5.x Laravle 5.1 Laravle 5.4 Laravle 5.2 Laravle 5.3 confirmation prompt

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.

@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">

Javascript to show the confirm prompt

Place below javaScript in your page footer area.

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