With an eloquent model you can update data simply by calling
$model->update( $data );
But unfortunately this does not update the relationships.
If you want to update the relationships too you will need to assign each value manually and call push() then:
$model->name = $data['name'];
$model->relationship->description = $data['relationship']['description'];
$model->push();
Althrough this works it will become a mess if you have a lot of data to assign.
I am looging for something like
$model->push( $data ); // this should assign the data to the model like update() does but also for the relations of $model
Can somebody please help me out?
You may try something like this, for example a
Client
model and anAddress
related model:There are other ways to save relation. You may check this answer for more details.
You can implement the observer pattern to catch the "updating" eloquent's event.
First, create an observer class:
Then assign it to your model
And when you will call the update method, the "updating" event will be fired, so the observer will be triggered.
See the laravel documentation for the full list of events.