-
-
Save vothanhkiet/d7fd6a4e58776e2cd9c5952b93e8b05d to your computer and use it in GitHub Desktop.
Delete Modal Popup with Laravel, Bootstrap and jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function index(){ | |
$categoryList = Category::all(); | |
return view('category.list')->with('categoryList', $categoryList); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('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(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment