vendredi 18 décembre 2015

Laravel - Get latest changes to object and log them

Is there an easy way to check the changes an object in eloquent went through? I'm trying to avoid iterating over the new object and comparing each item with old values.

For example, if I am given:

$user = User::find($id);

$user->name = $new_name;
$user->roles()->sync($new_roles);
$user->save();

My current solution is to store the $user data on Line 1 into an $old_user variable and iterating through the data and checking the values.

Now this might be Ok for this example but in reality that user has a lot more relationships and a lot more data to look through, so I want to know if there's a better way to solving this issue.

Any help is much appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire