Skip to content

Instantly share code, notes, and snippets.

@milon
Last active April 24, 2026 08:30
Show Gist options
  • Select an option

  • Save milon/030f12aaaf54dd178657 to your computer and use it in GitHub Desktop.

Select an option

Save milon/030f12aaaf54dd178657 to your computer and use it in GitHub Desktop.
Delete Modal Popup with Laravel, Bootstrap and jQuery
public function index(){
$categoryList = Category::all();
return view('category.list')->with('categoryList', $categoryList);
}
<div>
@include('modal')
<table class="table table-bordered table-striped table-hover category-table" data-toggle="dataTable" data-form="deleteForm">
<thead>
<tr>
<th>Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach($categoryList as $category)
<tr>
<td>{{ $category->category_name }}</td>
<td>
<a href="{{ route('categories.edit', $category->id) }}" class="btn btn-info btn-xs">{{ trans('categories.edit') }}</a>
{!! Form::model($category, ['method' => 'delete', 'route' => ['categories.destroy', $category->id], 'class' =>'form-inline form-delete']) !!}
{!! Form::hidden('id', $category->id) !!}
{!! Form::submit(trans('categories.delete'), ['class' => 'btn btn-xs btn-danger delete', 'name' => 'delete_modal']) !!}
{!! Form::close() !!}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="modal" id="confirm">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Delete Confirmation</h4>
</div>
<div class="modal-body">
<p>Are you sure you, want to delete?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-sm btn-primary" id="delete-btn">Delete</button>
<button type="button" class="btn btn-sm btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
$('table[data-form="deleteForm"]').on('click', '.form-delete', function(e){
e.preventDefault();
var $form=$(this);
$('#confirm').modal({ backdrop: 'static', keyboard: false })
.on('click', '#delete-btn', function(){
$form.submit();
});
});
@webineh

webineh commented Jun 13, 2017

Copy link
Copy Markdown

very thanks

@abiblair

Copy link
Copy Markdown

Just what I needed, Many thanks!

@ldt1992

ldt1992 commented Aug 10, 2017

Copy link
Copy Markdown

wow, It's work. Thank you so much.

@mengheang168

Copy link
Copy Markdown

I am a stater of laravel, when I did it . it is not working please help me

@mengheang168

Copy link
Copy Markdown

File script.js? => in the code not see others file call file script.js to use so how can it work?

ghost commented Oct 3, 2017

Copy link
Copy Markdown

Just what I needed, Thank you so much.

@sadrbox

sadrbox commented Jan 9, 2018

Copy link
Copy Markdown

Very Thanks!!! Perfect!

@juanpablopisano

Copy link
Copy Markdown

Brillante

@jasonbjm

Copy link
Copy Markdown

Thank you so much , Perfect!

@duartejean

Copy link
Copy Markdown

Thanks!

@andi79h

andi79h commented Feb 8, 2018

Copy link
Copy Markdown

It didn't work for me right away yet after some debugging it works as long as I wrap the javascript part in document.ready like so:

  $(document).ready(function () {
       $('table[data-form="deleteForm"]').on('click', '.form-delete', function(e){
           e.preventDefault();
           var $form=$(this);
           $('#confirm').modal({ backdrop: 'static', keyboard: false })
                   .on('click', '#delete-btn', function(){
                       $form.submit();
                   });
       });
   });

However, awesome snip! Thanks a lot 👍

@MallonEmanuel

Copy link
Copy Markdown

Gracias!

@zawyelwin

Copy link
Copy Markdown

Thanks.

@syrfn

syrfn commented May 2, 2018

Copy link
Copy Markdown

Thank you so much! Very helpful! :)

@RafaelMeirim

RafaelMeirim commented May 5, 2018

Copy link
Copy Markdown

Very good, I just have a question, how can I pass the name to the modal?
Ex:
<p> Are you sure you want to delete? NAME to be deleted </ p>

@MehranLabour

Copy link
Copy Markdown

Awesome...

@kielboy8

kielboy8 commented Jul 23, 2018

Copy link
Copy Markdown

Although this would work if the delete button was the only button in the form. If there were other buttons like 'Edit' or 'View', there would be a conflict where the form will show the delete modal upon click.

If you transfer the form to only have the Delete button inside it, it would fix the issue but there would be an inconsistency with the design where the delete button will appear at the next line.

To fix this, just add
form { display: inline; }

@arifhossainsikder

Copy link
Copy Markdown

Thanks, it works :)

@Briuor

Briuor commented Oct 27, 2018

Copy link
Copy Markdown

Thank you!

@ahmadrio

Copy link
Copy Markdown

terima kasih

@Krishnan7027

Copy link
Copy Markdown

Thanks alot. This was so precise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment