create dynamically checkbox in blade

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

from Newest questions tagged laravel-5 – Stack Overflow https://ift.tt/3FbLayD
via IFTTT

Related Posts

Codeigniter : Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE) in Laravel project

I’m getting following error: **Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE)** Note : It’s working in local but facing issue in production server. private…

Firebase receive notification while tab is active or on focus

What i want is to be able to perform an action when a user receives a notification while the browser is open and tab is active or…

Laravel’s alias loader does not find class

We have a legacy project that we cannot update and we need to make some changes in symfony’s Response.php in vendor. We have solved this by copying…

Laravel 5 – generic document management

I have a system where you can create different types of unique documents. For instance, one document is called Project Identified and this expects certain inputs. Originally,…

Laravel Nova limit the results in indexQuery

I ran intro a situation where I need to limit the results of a resource to only 3 results. To be more specific, based on the logged…

Auditoria en laravel 5.8 [closed]

Cómo puedo automatizar el registro de actividades de un usuario en laravel? Si un usuario ingresa a un app de laravel, debo guardar toda su actividas, a…

Leave a Reply

Your email address will not be published.