Hi gladly I want to delete only checked tasks. So to achieve that I use an array variable for the name attribute for my checkbox.
At the moment I have this:
<div class="dropdown">
<button type="button" class="btn btn-danger dropdown-toggle selDelete" data-toggle="dropdown" id="deleteTask">
<input id="check1" name="deleteCheckedTask[]" type="checkbox" class="check" value="{{$Task->id}}">
<span class="caret-hover caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="selDelete" role="menu">
<li><a class="deleteTask" href= "{{ route('user.tasks.destroy',array( $Task->id )) }}" data-method="delete" >Deletey</a></li>
</ul>
</div>
Which looks like this in the browser: link: http://i.imgur.com/Sv8l3OX.png
But this wil only send the id of 1 task that's going to be deleted.
I have also tried this:
<div class="dropdown">
<button type="button" class="btn btn-danger dropdown-toggle selDelete" data-toggle="dropdown" id="deleteTask">
<input id="check1" name="deleteCheckedTask[]" type="checkbox" class="check" value="{{$Task->id}}">
<span class="caret-hover caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="selDelete" role="menu">
<li><a class="deleteTask" href= "{{ route('user.tasks.destroy',array( $deleteCheckedTask)) }}" data-method="delete" >Deletey</a></li>
</ul>
</div>
But then I get the error undefined variable, here is a screenshot of the error: http://i.imgur.com/QW5De7y.png
And this is how my delete() from TasksController.php currently looks like:
public function destroy($id){
//$deleteCheckedTasks=array();
$deleteCheckedTasks=Input::get('deleteCheckedTask');
//die(print_r(Input::get('deleteCheckedTask')));
foreach ($deleteCheckedTasks as $key => $value ) {
print 'val: '. $key ;
}
//$row= DB::table('ordertasks')->where('id', $id)->first();
//Task::destroy($id);
//Task::destroy($row->id_task);
//Ordertask::destroy($id);
//delete werkt niet op vu nam zijn pc
if (Request::path()=='api/v1/tasks/'.$id) {
return Response::json(array(
'error' => false,
'tasks' => 'task deleted'),
200
);
}
return Redirect::route('user.tasks.index');
}
I know how I can do this with jQuery, but I gladly want to do this with Laravel. Can someone help me, please? I think that I'm very close.
Maybe I am wrong but I don't see an HTML form here and it looks like you are trying to submit the checkboxes using a link.
<form action="{{ route('user.tasks.destroy',array( $Task->id )) }}" method="post" >
<div class="dropdown">
@foreach($LIST_OF_ITEMS_TO_DELETE as $ITEM_TO_DELETE)
<input id="check1" name="deleteCheckedTask[]" type="checkbox" class="check" value="{{$ITEM_TO_DELETE->id}}">
<span class="caret-hover caret"></span>
@endforeach
<ul class="dropdown-menu" aria-labelledby="selDelete" role="menu">
<li><input type="submit" value="Delete Selected" /></li>
</ul>
</div>
</form>
Hi thanks for your answer and I see what you mean. I wanted to test your code but it changed the layout of the buttons: link: http://i.imgur.com/ESqYpVe.png
I think it's because of the submit button (which I also don't see in the browser for some reason). I'm really tired at the moment, so I'm going to sleep now.
Why do you have the checkbox in a button?
I would have one checkbox per row, then a single "delete selected" button which submits the form
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community