2
I am creating a form and need to send to the bank the selected checkbox. I have the table conta
, conta_categoria
and categoria
. In the conta_categoria
have the id_conta
and the id_categoria
.
How would I send all the data from checkbox selected to the table conta_categoria
?
My form create.Lade
<div class="form-group">
{!! Form::label('descricao', 'Categoria: ') !!}
@foreach (Realito\Categoria::all() as $categoria)
<br>
{!! Form::checkbox('descricao[]',$categoria->id_categoria) !!}
{{ $categoria->id }}
{{ $categoria->descricao }}
</br>
@endforeach
</div>
My account controller where you are entering the data
if($bill->save()){
$contasCategoria = new \App\ContasCategoria();
$contasCategoria->id_conta = $ultimoID;
$contasCategoria->id_categoria = $request->get('categoria[]');
// $contasCategoria->id_categoria = $codCategoria;
$conta->contasCategoria()->save($contasCategoria);
}
Good.. I couldn’t do exactly how you still spoke with doubt.. I even saved it in the database when you selected only one.. but not with the array. I did not hit foreach to add arrays if($account->save()){

 $contasCategoria = new \Realito\ContasCategoria();

 $contasCategoria->id_conta = $ultimoID;

 $contasCategoria->id_categoria = $request->get('categoria');

 $conta->contasCategoria()->save($contasCategoria);
&#xTo; }
– raphael
updates your question with the current code.
– Euler01
Ready... giving dd($request) it returns me the selected fields
– raphael
na viu you will name the field 'Description[]' (with bracket). But in the controller you will use $request->get('category'); (no bracket).
– Euler01
Do the following, from a dd($request->get('category'));
– Euler01
I did that and he brought me the 4 selected categories, only remaining to send the 4 to the bank
– raphael
Just you make a go or foreach now, saving one by one.
– Euler01
this foreach that I’m not doing right..
– raphael
a glance, I added the code in my reply. See if this resolves.
– Euler01
thank you. had just resolved would close topic. But mt thanks for the help.. was of great use!
– raphael
You’re welcome, buddy. A hug.
– Euler01