input checkboxes (checked) from array associative
I need to checked multiple input checkbox from an array
this $rol->permisos show this array:
array:2 [▼
"editar-usuario" => true
"editar-rol" => true
]
@foreach ($rol->permisos as $key => $permiso)
<input type="checkbox" name="" value="" {{ $key == 'editar-rol' ? 'checked' : ''}}>1
<input type="checkbox" name="" value="" {{ $key == 'crear-rol' ? 'checked' : ''}}>2
@endforeach
but this code show 6 input (it multiplies the quantity items in the array)
You don't need a foreach:
<input type="checkbox" name="" value="" {{ !empty($rol->permisos['editar-rol'] ? 'checked' : ''}}>1
<input type="checkbox" name="" value="" {{ !empty($rol->permisos['editar-rol'] ? 'checked' : ''}}>2
Why you have checkbox with editar-rol twice?
@Cinek thanks, and this input editar-rol was a mistake
Please or to participate in this conversation.