0
So friends all right with you, I’m starting in Laravel and I’m not getting to solve a problem that should be simple.
I have a view
which inserts data into db
with a form built through the collective
and a single checkbox that saves 0 or 1 in the field.
So far so good, recording correctly. However when I use the same form for editing the records, if I set any value in the checkbox when updating the data it saves what is in the value `` defined in collective
in the case within the second parameter $pessoa->cliente
, inside 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 that I have accomplished here it has saved the value information that I define within the collective
as if it did not consider the value of the checkbox set in javascript and only what I set as value in collective
.
if I define the form as follows:
{!! Form::label('cliente', 'Cliente') !!}
{!! Form::checkbox('cliente', 'teste' , null, ['onclick' => 'myFunction()'']) !!}
it saves test even if there in the browser when I click on the checkbox it sets another value to the same ... I’m sorry but I hope I’ve been clearer this time.
Follows the method of Controller
.
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!');
}
Follows the passage from view
:
{!! Form::label('cliente', 'Cliente') !!}
{!! Form::checkbox('cliente', $pessoa->cliente , null, ['onclick' => 'myFunction()','div' => 'cliente']) !!}
Is your doubt confused? could improve
– novic
Let me try to summarize using form creator to create checkbox {!! Form::checkbox('client', '',null, ['onclick' => 'myFunction()','div' => 'client']) !! } it saves what it has set in the second parameter that in the example above this empty '', in my edit view I need to bring the value in the checkbox, something like this $person->id but when I call the method of updating the data it does not check what is set in my "html" I inspect the element .. it saves what is set in the value parameter then in the case of the above empty example ''
– Andrew Palmeira
You have to put the controllers the model and your View in the question is to explain on top of that.
– novic
See if you’ve improved now
– Andrew Palmeira