This question already has an answer here:
I have a User
model and a UserInfo
model. they are a one to one relationship.
When a user signs up, he then goes ahead to fill a very large form with more info. That is contained in the user_info
table, represented by UserInfo
model.
I currently do this
$user->user_info()->create($request->all());
it works but if it is run the second time, it creates andother UserInfo
record for the same user.
Is there a way i can do it so that if the UserInfo record already exists for this user, it only updtes the exisiting one
Is there a method like updateOrCreate
that can work with Mass Assignment like this?
So that if the UserInfo
record already exist on this User
, it just updates with these new values
</div>