Ask Database transaction

I have resource with createpage and inside createpage i using life cycle before and after create and my question is, is that really using databasetransaction wrapped before and after create ?? i have already configured inside panel for ->databasetransactions(true) btw thx u all
No description
2 Replies
Patrick
Patrick3mo ago
If you take a peek in CreateRecord
public function create(bool $another = false): void
{
$this->authorizeAccess();

try {
$this->beginDatabaseTransaction();

$this->callHook('beforeValidate');

$data = $this->form->getState();

$this->callHook('afterValidate');

$data = $this->mutateFormDataBeforeCreate($data);

$this->callHook('beforeCreate');

$this->record = $this->handleRecordCreation($data);

$this->form->model($this->getRecord())->saveRelationships();

$this->callHook('afterCreate');

$this->commitDatabaseTransaction();
} catch (Halt $exception) {
$exception->shouldRollbackDatabaseTransaction() ?
$this->rollBackDatabaseTransaction() :
$this->commitDatabaseTransaction();

return;
} catch (Throwable $exception) {
$this->rollBackDatabaseTransaction();

throw $exception;
}

$this->rememberData();

$this->getCreatedNotification()?->send();

if ($another) {
// Ensure that the form record is anonymized so that relationships aren't loaded.
$this->form->model($this->getRecord()::class);
$this->record = null;

$this->fillForm();

return;
}

$redirectUrl = $this->getRedirectUrl();

$this->redirect($redirectUrl, navigate: FilamentView::hasSpaMode() && is_app_url($redirectUrl));
}
public function create(bool $another = false): void
{
$this->authorizeAccess();

try {
$this->beginDatabaseTransaction();

$this->callHook('beforeValidate');

$data = $this->form->getState();

$this->callHook('afterValidate');

$data = $this->mutateFormDataBeforeCreate($data);

$this->callHook('beforeCreate');

$this->record = $this->handleRecordCreation($data);

$this->form->model($this->getRecord())->saveRelationships();

$this->callHook('afterCreate');

$this->commitDatabaseTransaction();
} catch (Halt $exception) {
$exception->shouldRollbackDatabaseTransaction() ?
$this->rollBackDatabaseTransaction() :
$this->commitDatabaseTransaction();

return;
} catch (Throwable $exception) {
$this->rollBackDatabaseTransaction();

throw $exception;
}

$this->rememberData();

$this->getCreatedNotification()?->send();

if ($another) {
// Ensure that the form record is anonymized so that relationships aren't loaded.
$this->form->model($this->getRecord()::class);
$this->record = null;

$this->fillForm();

return;
}

$redirectUrl = $this->getRedirectUrl();

$this->redirect($redirectUrl, navigate: FilamentView::hasSpaMode() && is_app_url($redirectUrl));
}
so yes, it is wrapped in a transaction
jepewsykes
jepewsykesOP3mo ago
okk thx u bro
Want results from more Discord servers?
Add your server