Skip to content

Instantly share code, notes, and snippets.

@hugofabricio
Last active January 2, 2018 12:42
Show Gist options
  • Save hugofabricio/31e734ee8c5bc8711e9cf63c99863d17 to your computer and use it in GitHub Desktop.
Save hugofabricio/31e734ee8c5bc8711e9cf63c99863d17 to your computer and use it in GitHub Desktop.
<?php
// Controller
public function edit($id)
{
//passar o model com id
$usu = User::find($id);
$perf = Perfil::all();
$oper = Operacao::all();
// Get building categories
$user_opps = [];
foreach($usu->operacaos as $opp):
$user_opps[$opp->Operacao_ID] = true;
endforeach;
return view('usuario.edit', compact('usu', 'perf', 'oper', 'user_opps'));
}
// View
<div class="input-group">
@foreach($oper as $opp)
@if($opp->Operacao_Status == 1 && $usu->perfil_id == 2)
<input type="checkbox"
name="ids_operacoes[{{ $opp->Operacao_ID }}]"
value="{{ $opp->Operacao_ID }}"
{{ isset($user_opps[$opp->Operacao_ID]) ? 'checked' : '' }}
/>
{{ $opp->Operacao_Status }} {{ $opp->Operacao_Descricao }}
@endif
@endforeach
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment