Luke Sweeney Luke Sweeney - 5 months ago 23x
PHP Question

Laravel foreach loop not outputting to form

Here is a form from my Laravel 5 project:

<form class="form-group" action="/counselors/{{ $counselor->id }}/badges/add" method="post">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
@foreach($badges as $badge)
<div class="input-group">
<span class="input-group-addon">
<input type="checkbox" style="float: left" value="{{ $badge->id }}">&nbsp;{{ $badge->name }}
<input type="submit" class="form-control btn btn-primary" name="submit" value="Submit"><hr>
<input type="button" class="form-control btn btn-danger" name="cancel" value="Cancel" onClick="location='/counselors'">

The $badges is a collection of badges from a database. They all iterate and display properly, but when i look at the request data with


it returns:


It doesn't include the checkbox data from the loop. Is this incorrect? What's the best way to do this? There are 160 items in the $badges collection.

I'm pretty new so please go easy.


put name attribute to the input checkbox and giv it a value

<input type="checkbox" name="check-{{ $badge->id }}" style="float: left" value="{{ $badge->id }}">&nbsp;{{ $badge->name }}

Note : here i use the name "check-" and the id of the badge to get defferent name for each checkbox