I'm trying to implement checkbox and laravel collective in my form but I get only single value in form, any ideas how to fix it
{!! Form::open(array('action'=>'UserController@updateInfo','method'=>'post')) !!}
Workdays:
<br>
{!! Form::label('monday', 'Monday') !!}
{!! Form::checkbox('workday', 'monday') !!}
<br>
{!! Form::label('tuesday', 'Tuesday') !!}
{!! Form::checkbox('workday', 'tuesday') !!}
<br>
{!! Form::label('wednesday', 'Wednesday') !!}
{!! Form::checkbox('workday', 'wednesday') !!}
<br>
{!! Form::label('thursday', 'Thursday') !!}
{!! Form::checkbox('workday', 'thursday') !!}
<br>
{!! Form::label('friday', 'Friday') !!}
{!! Form::checkbox('workday', 'friday') !!}
<br>
{!! Form::label('saturday', 'Saturday') !!}
{!! Form::checkbox('workday', 'saturday') !!}
<br>
{!! Form::label('sunday', 'Sunday') !!}
{!! Form::checkbox('workday', 'sunday') !!}
<br>
{!! Form::submit('Save', $attributes = ['class'=>'button']) !!}
{!! Form::close() !!}
when I print my request i only get single output (eg. selected monday friday I get only friday when request is processed)
also labels not working - ideas on that too?
You're using the same name (workday) for all your checkboxes. That's why it's only showing the last checkbox with that name
Just change all names to workday[] instead.
{!! Form::checkbox('workday[]', 'monday') !!}
This will return all selected checkbox in an array.
Try this:
You used same name for every checkbox
when you checked
multiple checkbox
you only get the last value.
{!! Form::open(array('action'=>'UserController@updateInfo','method'=>'post')) !!}
Workdays:
<br>
{!! Form::label('monday', 'Monday') !!}
{!! Form::checkbox('workday[]', 'monday') !!}
<br>
{!! Form::label('tuesday', 'Tuesday') !!}
{!! Form::checkbox('workday[]', 'tuesday') !!}
<br>
{!! Form::label('wednesday', 'Wednesday') !!}
{!! Form::checkbox('workday[]', 'wednesday') !!}
<br>
{!! Form::label('thursday', 'Thursday') !!}
{!! Form::checkbox('workday[]', 'thursday') !!}
<br>
{!! Form::label('friday', 'Friday') !!}
{!! Form::checkbox('workday[]', 'friday') !!}
<br>
{!! Form::label('saturday', 'Saturday') !!}
{!! Form::checkbox('workday[]', 'saturday') !!}
<br>
{!! Form::label('sunday', 'Sunday') !!}
{!! Form::checkbox('workday[]', 'sunday') !!}
<br>
{!! Form::submit('Save', $attributes = ['class'=>'button']) !!}
{!! Form::close() !!}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With