Values are not being audited when using DB::beginTransaction #913
Unanswered
alexfarrugia
asked this question in
Q&A
Replies: 2 comments
-
i noticed that this was actually happening when i was using update statements with DB::raw - maybe this could be the reason and not the usage of the DB transaction command?
|
Beta Was this translation helpful? Give feedback.
0 replies
-
I'm using $payment=PaymentModel::query();
$payment->update([
'amount' => DB::raw('amount - allocated_amount'),
]);
// this is not audited because is a bulk update, and it doesn't trigger laravel update event |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Actual Behaviour
I am making changes to some models which use the Auditable trait within the context of a db transaction. I need to do this because there are chunk of changes which are happening and i need to be able to rollback if something goes wrong. I have noticed that the changes to the values of these models are being audited as empty objects. (see example in this image)
Could it be that the audits are happening before the changes are being committed to the database or maybe am i missing something myself?
Expected Behaviour
I would expect that the correct new values are being audited in the database.
Steps to Reproduce
`DB::beginTransaction();
try {
$fund->amount = 5000;
$fund->save();
.....
DB::commit();
}`
Possible Solutions
Not sure if there is a way of delaying the audit until the actual transaction is committed perhaps ? I can't think of any other way to somehow include the audit within the same database transaction?
thanks
Beta Was this translation helpful? Give feedback.
All reactions