Closed omerbaskurt closed 11 months ago
Maybe it's because update
uses dirty
, and after saving, dirty
is empty
Try this way
$article->title = $newTitle;
event('eloquent.updated: App\Models\Article', $article);
$article->saveQuietly();
Thanks, that does the trick. But it kinda defeats the purpose of not firing events on save. We do fire the events after the business logic block. Something like this:
$article->title = $newTitle;
$article->saveQuietly();
$events[] = ['updated', 'App\Models\Article', $article];
$user->restoreQuietly();
$events[] = ['restored', 'App\Models\User', $user];
... a bunch of other operations without events while saving event data
// then fire the events
foreach ($events as $event) {
event('eloquent.' . $event[0] . ': ' . $event[1], $event[2]);
}
Did you try clone
before save??
$article->title = $newTitle;
$events[] = ['updated', 'App\Models\Article', clone $article];
$article->saveQuietly();
I can't give you a specific answer if you don't specify the full scenario
Using clone
on the event works, thank you.
I update a property of a model and
saveQuietly
to not to trigger events on the save. Then, manually fire the update event later. I expect anupdate
audit getting triggered but it doesn't.created
,restored
,deleted
events work as expected.updated
is included in the audit config file (audit.php)