Edit record in the database

0

I'm trying to edit a Form using fill()->save() but instead of updating it Laravel 5 tries to make 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?

    
asked by anonymous 17.03.2015 / 16:21

1 answer

3

Place a larger snippet of code. In order for Eloquent to recognize as an update, you need to give GET the object before, otherwise it will be considered as a new record because it has no% / p>

Ex :

$model = Model::find(1);
$model->fill($input);
$model->save();
    
17.03.2015 / 22:57