I´m traying to create list of checkbox in my blade with all roles that i have in my DB
. I´m doing loop to get all roles and if to check that roles have this user that i´m doing edit:
@foreach($roles as $rol)
@foreach ($selRoles as $role)
@if ($role == $rol->id)
<div class="col-md-4">
<input type="checkbox" name="rol" checked=checked class="form-check-input" value="" id="">
</div>
@else
<div class="col-md-4">
<input type="checkbox" name="rol" class="form-check-input" value="" id="">
</div>
@endif
@endforeach
@endforeach
With this code, my problem it´s that all my roles it´s duplicated. In my controller i have this:
public function edit(User $usuario)
{
$roles = Bouncer::role()->orderBy('title', 'DESC')->get();
$selRoles = $usuario->roles->pluck('id')->toArray(); //selRoles it´s roles from user
$usuario->load('roles');
return view('admin.empleados.edit', compact('usuario', 'roles','selRoles'));
}
and retult in blade it´s:
teleoperadora
teleoperadora
teleoperadora
repartidor
repartidor
repartidor
prueba
prueba
prueba
Jefe de equipo
Jefe de equipo
Jefe de equipo
jefa-sala
jefa-sala
jefa-sala
instalador
instalador
for example. I don´t know that i´m doing bad for get this result in my blade. Anybody can help me please?
Thanks for read and help. Sorry for my english
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire