I have the next relationship User hasMany Contacts
.
In normal situation is use $user->contacts()->save($contact)
to add and save a contact to the user, but I need to associate contacts to users without save the models (User and Contacts).
edit:
I need to build a plant that receives one of such methods and return an XML a collection of templates, only in some of these models will be stored at postiriori.
You can use the associate
on your model with belongsTo
.
$contact= Contact::find(10);
$user->account()->associate($contact);
$user->save(); // You do need to update your user
Source: http://laravel.com/docs/eloquent
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With