4
I have the following function :
public function alterar($id)
{
$produto = Produto::find($id);
$params = $request->all();
$produto->fill($params)->save();
return redirect()->action('ProdutoController@index');
}
but every time I change a product, a new one of it is added in the bank (a new updated copy) and the old one is still there, so what’s happening is a copy and not effectively updating that product?
Is the id you are receiving correct with the search in the bank? Try to use
findOrFail
instead offind
to see if any mistakes are made– gmsantos
Check if the database does not have any Rigger doing Insert because I see no error in your code.
– Miguel Batista
Instead of using
find
, usefindWhere
, maybe that’s the solution.– cleiton lopes