Support the ongoing development of Laravel.io →
Views Blade Forms
Last updated 2 years ago.
0

well if it is true then it is checked, why wouldn't it be ?

0

Hi Lagobx,

Thanks for the answer. I re-tried this morning and everything was fine. I thought I was crazy yesterday but I found what broke up the form. If the name of the checkbox is roles[] then it returns true every time. But if I change it for rolescheck[] it is ok. May be a stupid, but do you know why ? Here is the code :

{!! Form::label('role_id', 'Roles:') !!}
<br/>
@foreach($roles as $keyrole => $role)
    {!! Form::checkbox('rolescheck[]', $keyrole, (false !== $user->is($role)) ? 'true' : '' ) !!} 	{!! $role !!} (input name : rolescheck[] )
    <br/>
    {!! Form::checkbox('roles[]', $keyrole, (false !== $user->is($role)) ? true : '' ) !!} 	{!! $role !!} (input name roles[] )
    <br/><br/>
@endforeach

And here is the output :

<label for="role_id">Roles:</label>

<input name="rolescheck[]" type="checkbox" value="1">   Administrator (input name : rolescheck[] )
<input checked="checked" name="roles[]" type="checkbox" value="1">  Administrator (input name roles[] )

<input checked="checked" name="rolescheck[]" type="checkbox" value="2">   Editor (input name : rolescheck[] )
<input checked="checked" name="roles[]" type="checkbox" value="2">  Editor (input name roles[] )


<input name="rolescheck[]" type="checkbox" value="3">   User (input name : rolescheck[] )
<input checked="checked" name="roles[]" type="checkbox" value="3">  User (input name roles[] )
0

are you using form model binding by any chance ?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

geekosophe geekosophe Joined 28 Jun 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.