我是删除多个复选框的新手,所以我需要一些帮助。我已经在网上搜索了几个小时,但我无法解决问题。
我有一个待办事项列表,我的网页上有一些todo显示在数据库中。如何在一次点击中删除所有选中的复选框?
我正在使用 Laravel 5.4
ToDoController:
public function destroy()
{
$checked = Request::input('checked')['checked'];
$checked->delete();
}
刀片:
@foreach ($todo as $todoresult)
<form method="get" action="/todo/destroy/">
<div class="checkbox">
<label><input type="checkbox" value="{{$todoresult->id}}" name="checked[]">{{$todoresult->todoinfo}}</label><br />
</div>
@endforeach
</div>
<div class="panel-footer">
<button class="btn btn-success" type="submit">Verwerken</button>
</form>
路线:
Route::get('/todo/destroy/', 'ToDoController@destroy');
我该怎么做?我的路由怎么样?
答案 0 :(得分:4)
以下内容可能会起作用:
addFilter = function (spec, all_vis){
var contain_div = document.createElement('div');
var visualisation_spec = document.createElement('div');
for(var i=0;i< all_vis.length; i++) {
if(contains(spec.vis_list, all_vis[i])){ // This is a custom function
var check = document.createElement('input')
check.type = 'checkbox';
check.value = all_vis[i];
check.checked = true;
visualisation_spec.append(check);
visualisation_spec.innerHTML += all_vis[i] +"<br>"//this isnt quite how i
//create the label
}
}
contain_div.append(visualisation_spec)
// .... MORE INTERFACE CREATION
...
return contain_div;
// This interface segment is returned and attached to others before being
// added to the DOM
}
答案 1 :(得分:4)
您不需要循环查询。 您可以使用WhereIn删除多个ID
public function destroy() {
$checked = Request::input('checked',[]);
Todo::whereIn("id",$checked)->delete();
}