1
I’m trying to create a update
with Laravel 5.1 but is bringing the following error:
Type error: Argument 1 passed to Illuminate\Database\Eloquent\Builder::update() must be of the type array, object given
Follows my Controller
public function update($id)
{
$proposta = $this->proposta;
$proposta->cliente_id = $this->request->get('cliente_id');
$proposta->contato = $this->request->get('contato');
$proposta->email = $this->request->get('email');
$proposta->telefone = $this->request->get('telefone');
$proposta->fatcnpj = $this->request->get('fatcnpj');
$proposta->atendimento = $this->request->get('atendimento');
$proposta->dt_solicitacao = $this->request->get('dt_solicitacao');
$proposta->dt_vigencia = $this->request->get('dt_vigencia');
$proposta->vendedor = $this->request->get('vendedor');
$proposta->coleta = $this->request->get('coleta');
$proposta->dt_integracao = $this->request->get('dt_integracao');
$proposta->hr_integracao = $this->request->get('hr_integracao');
$proposta->frete_material = $this->request->get('frete_material');
$proposta->status_id = $this->request->get('status_id');
$this->proposta->where('id', $id)->update($dadosForm);
$dadosForm = $this->request->except('_token');
$proposta_id = $id;
$count = $this->ensaios->max('id');
for($i=1;$i<=$count;$i++){ //Save Ensaios
$proposta_ensaios = new PropostaEnsaios();
$proposta_ensaios->id_proposta = $proposta_id;
$proposta_ensaios->id_produto = $i;
$proposta_ensaios->quantidade = $dadosForm['quantidade_'.$i];
$proposta_ensaios->valor= $dadosForm['valor_'.$i];
$proposta_ensaios->total = $dadosForm['total_'.$i];
$proposta_ensaios->where('id', $id)->update($dadosForm);
}
in which of the two updates exactly happens this?
– Neuber Oliveira
Don’t you just save? in
$proposta->save()
????– novic
@Neuberoliveira in the First but the second is the same will happen the same thing
– Shaolin Fantastic
@Virgilionovic the $proposta->save() it try to give an Insert and not an update
– Shaolin Fantastic
@Shaolinfantastic ai has for minors, I can even feel new instance make her update instead of Insert, of course I understand what you said because I would do totally different bringing the direct instance of research with a
find(1)
and then changed, so your code just needs to be tidied up to solve your problem is that I’m sorry I didn’t find the fil of the skein !– novic
Example here I would do:
$proposta = $this->proposta->find(1);
; is already in update mode changing the fields and giving a$proposta->save();
I believe it solves that part of the problem! @Shaolinfantastic– novic
@Virgilionovic I believe the update works because the
$id
ends up beingnull
, ai when it arrives at the bank, probably the id is auto increment, then when it receives null continues the sequence– Neuber Oliveira
@Neuberoliveira did not understand what you just wrote as a comment.
– novic
Something that can work too, for a little while I do not move with Aravel, since it is populating the object before, try so,
$this->proposta->where('id', $id)->update()
– Neuber Oliveira