Search code examples
laravelcheckboxlaravel-5formslaravelcollective

laravel collective checkbox form


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?


Solution

  • 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.