Then friends are fine with you, I'm starting in Laravel and I'm not able to solve a problem that should be simple.
I have a view
that inserts data in db
with a form built through collective
and a single checkbox that saves 0 or 1 in the field.
So far so good, recording properly. But when I use the same form for editing the records, if I set any value in the checkbox at the time of updating the data it saves what is in the value '' defined in the collective
in the case within the second parameter $pessoa->cliente
, within my view
I having a javascript function that when I mark or uncheck the checkbox it changes the value
in the form.
by the tests I've done here it has saved the information of the value that I set inside collective
and as if it did not consider the value of the checkbox defined in javascript and only what I set to value in collective
.
If I set the form as follows:
{!! Form::label('cliente', 'Cliente') !!}
{!! Form::checkbox('cliente', 'teste' , null, ['onclick' => 'myFunction()'']) !!}
it saves test even if it in the browser when I click on the checkbox it set another value for the same ... I apologize and hopefully it was clearer this time.
The Controller
method follows.
public function atualizar($id, Request $request){
$pessoa = Pessoa::findOrfail($id);
$pessoa = $pessoa->update($request->all());
return Redirect::to('pessoas/' . $id . '/editar');
\Session::flash('mensagem_sucesso_atu', 'Atualizado com sucesso!');
}
Follow the excerpt from view
:
{!! Form::label('cliente', 'Cliente') !!}
{!! Form::checkbox('cliente', $pessoa->cliente , null, ['onclick' => 'myFunction()','div' => 'cliente']) !!}