Save Related Models (One to One) - Laravel 5.1

0

I have a Model Info and a Model Complement that are listed one by one.

The relationships are already working properly, I can pull the data and such, but I need to do an update and I do not know how.

Currently I get all the data in request , but I only do update of the infos table, as I would also update the data in the according to info to which it belongs?

    
asked by anonymous 14.04.2016 / 16:01

2 answers

1

I was able to resolve this issue as follows:

$complemento = Complemento::firstOrNew(['id_info' => $id]);

//requests...

$complemento->save();  

It was even better since I had to create the add-in if it did not exist.

    
18.04.2016 / 15:41
0

I'm pretty sure you can do it like this:

 $info = Info::findOrFail($id);

 $info->complemento->fill($request->all())->save();
    
15.04.2016 / 17:44