Php

i need to be able to update a model, and keep an old copy of it temporarily

guys, need a solution: i need to be able to update a model, and keep an old copy of it temporarily; seems when i use a replicated model, and call a relation on that model, laravel grabs the updated model. i want to generate an email that has the old info and new info (which is the same model), but somehow it falls apart as mentioned; i’m hoping to be able to keep the old model so i can leverage relations, etc, rather than do a data object
You already invited:

Daryl k

Upvotes from: agrath

how are you copying the object? You cant just say $object2 = $object;.  Then you just pass a reference, and the 2 will reference the same object
you have to do:  $object2 = clone $object;   Some basic testing using tinker seems to suggest this works as expected. I keep seeing the old values.

Menya Tom

Upvotes from:

if you eager load the relation, and then clone the object before you update it, doesnt that work?

CHINTAN PATEL

Upvotes from:

what are you trying to do there, if I might ask? (And did you get it working?)

If you wanna answer this question please Login or Register