0
I’m trying to edit a form using fill()->save()
but instead of updating Laravel 5 tries to do insert
and gives error saying that the record already exists in the table.
$input = $request->all();
$record->fill($input)->save();
I’m using rules: class MeuFormRequest extends Request
'nome' => 'required|unique:empresa,nome' . ($id ? ",$id" : '')
Does anyone have any idea what might be wrong?
Give first a find to search the data with those values, then you play the parameters as the new value and after a save. Ex: $user = User::find(1); $user->email = '[email protected]'; $user->save();. Or you can do direct User::Where('votes', '>', 100)->update(['status' => 2]);
– Allan Ramos
That’s what it was. Thanks!
– flp