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 Boivin15mo ago
Looks OK, are you running into any issues?
LancelotGamer
LancelotGamerOP15mo ago
Not at all. I am just asking if this is the correct way. Thank you
Want results from more Discord servers?
Add your server