我有一个表,它的数据是从这里的数据库中检索的:https ://imgur.com/Sv4Suo7 。我的问题是,我想删除复选框中选中的数据。
我尝试将 name="ids[]" 放在我的复选框中,但数据仍然没有发送到我的控制器。我在某处读到需要使用 Javascript,但我不知道如何使用。
意见:
<div class="box-header with-border">
<div class="box-header-tools pull-left" >
<a href="{{ url('tasks/create/')}}" class="tips text-green" title="{{ Lang::get('core.btn_create') }} ">
<i class="fa fa-plus-square-o fa-2x"></i></a>
<a href="{{ url('tasks/massDelete')}}" onclick="" class="tips text-red" title="{{ Lang::get('core.btn_remove') }}">
<i class="fa fa-trash-o fa-2x delete_all" data-toggle="confirmation" data-title="{{Lang::get('core.rusure')}}" data-content="{{ Lang::get('core.rusuredelete') }}" ></i></a>
</div>
</div>
<div class="box-body" >
<div class="table-responsive" style="min-height:300px; padding-bottom:60px; border: none !important">
<table class="table table-striped table-bordered " id="{{ $pageModule }}Table">
<thead>
<tr>
<th align="center" class="number"> No </th>
<th align="center"> <input type="checkbox" class="checkall" id="master" /></th>
<th align="center">Task</th>
<th align="center">Due Date</th>
<th align="center">Assigned To</th>
<th align="center">Assigned By</th>
<th align="center">Status</th>
<th align="center">{{ Lang::get('core.btn_action') }}</th>
</tr>
</thead>
<tbody> @foreach($tasks as $task)
<tr>
<td width="30"> {{ ++$i }} </td>
<td width="50"><input type="checkbox" class="checkbox" name="ids[]" value="{{$task->id}}" /></td>
<td><a href="{{ url('tasks/show/'.$task->id.'')}}" class="tips" title="{{ Lang::get('core.btn_view') }}">{{$task->task_name}} </a></td>
<td>{{$task->due_date}}</td>
@foreach($users as $user)
@if($user->id == $task->assigned_id)<td>{{$user->username}}</td>@endif
@endforeach
@foreach($users as $user)
@if($user->id == $task->assigner_id)<td>{{$user->username}}</td>@endif
@endforeach
@if($task->status == 0)<td width="90">
<span class="label label-block label-info label-sm">Ongoing</span>
</td>@endif
@if($task->status == 1)<td width="90">
<span class="label label-block label-danger label-sm">Cancelled</span>
</td>@endif
@if($task->status == 2)<td width="90">
<span class="label label-block label-success label-sm">Completed</span>
</td>@endif
<td>
@if($task->status == 0)
{!! Form::open(array('url'=>'tasks/completeStatus/'.$task->id, 'class'=>'form-horizontal')) !!}
<button type="submit" name="markcomplete" class="btn" ><i class="fa fa-check-circle-o fa-2x"></i></button>
{!! Form::close() !!}
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
<input type="hidden" name="md" value="" />
</div>
</div>
</div>
</div>
控制器:
public function massDelete(Request $request)
{
$gotids = $request->input('ids');
if($gotids){
foreach($gotids as $id){
$task = Tasks::findOrFail($id);
$task->delete();
}
}
return redirect('tasks');
}
路线:
Route::get('/tasks/massDelete/', 'TasksController@massDelete');
当我尝试 dd($gotids); 时,我希望数据在控制器中 它显示为空。希望任何人都可以提供帮助。