Is this the correct way to add a transaction when updating a model

protected function handleRecordUpdate(Model $record, array $data): Model
{
DB::transaction(function () use ($record, $data) {
$record->update($data);
});
return $record;
}
protected function handleRecordUpdate(Model $record, array $data): Model
{
DB::transaction(function () use ($record, $data) {
$record->update($data);
});
return $record;
}
I have an observer with {public $afterCommit = true;} property. Will this work ?
2 Replies
Patrick Boivin
Patrick Boivin10mo ago
Looks OK, are you running into any issues?
LancelotGamer
LancelotGamer10mo ago
Not at all. I am just asking if this is the correct way. Thank you