I would like to get the values for a series of checkboxes I have set up in a Laravel 4 form. Here is the code in the view setting up the checkboxes:
@foreac
If checkboxes are related then you should use [] in the name attribute.
@foreach ($friends as $friend)
<input tabindex="1" type="checkbox" name="friend[]" id="{{$friend}}" value="{{$friend}}">
@endforeach
$friends_checked = Input::get('friend');
if(is_array($friends_checked))
{
// do stuff with checked friends
}
Using name="friend[]" in the form field creates an array named friend that is passed to the server, as opposed to name="friend" which passes a string value to the server.
The array friend must have a key . If there is $friend->id you could try something like this.
@foreach ($friends as $friend)
<input tabindex="1" type="checkbox" name="friend[{{$friend->id}}]" id="{{$friend}}">
@endforeach