Skip to content

Instantly share code, notes, and snippets.

@ahmadshobirin
Created November 24, 2017 03:15
Show Gist options
  • Save ahmadshobirin/5744258a3b7866eb956115011c6640b7 to your computer and use it in GitHub Desktop.
Save ahmadshobirin/5744258a3b7866eb956115011c6640b7 to your computer and use it in GitHub Desktop.
multiple chekcbox delete
//view
<form action="you/url" method="get">
//this chekcbox on loop
<input type="checkbox" name="id[]" value="{{$gallery->id}}" id="child" class="child">
// chekcbox parent outside loop
<input type="checkbox" name="parent" id="parent">
//submit form
<button type="submit" class="btn btn-danger">Hapus</button>
</form>
--- jquery
<script>
$(document).ready(function () {
$("#parent").click(function () {
$(".child").prop("checked", this.checked);
});
$('.child').click(function () {
if ($('.child:checked').length == $('.child').length) {
$('#parent').prop('checked', true);
} else {
$('#parent').prop('checked', false);
}
});
});
</script>
--- on route
Route::get('you/url', 'youController@multipleDestroy');
-- on controller
public function multipleDestroy(Request $request)
{
dd($request->all());
foreach ($request->id as $key => $value) {
// echo $value."<br>";
$galleryDelete = GalleryModel::where('id', '=', $value)->delete();
}
return redirect()->back();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment