Reputation: 9942
I'm trying to create a logging trait that would also save all changes to relationships (many to many).
So far my idea is to store the model with all the relationships in static::updating event of the loggable model as $original. And then fetch the $original variable in static::updated event and compare the differences and log accordingly.
What would be a good way to go about doing this. If there's a better method to doing this I'm happy to hear about it.
Upvotes: 0
Views: 388
Reputation: 5135
you should define a public/protected
variable and assign value to that variable in updating
method, and access it in updated
method.
eg:
public var $storeTemp = null;
public function boot()
{
User::updating(function ($user) {
$this->storeTemp = $user->testVal; //or assign object
});
User::updated(function ($user) {
print_r($this->storeTemp);//print or access value
});
}
Upvotes: 2