F
Filament2mo ago
Hasith

Form Database Transactions

How i use DB transactions outside of filament inside my Livewire Component ? If Project create/update failed how i roll back relationship data insertions ?
public function create(): void
{
$data = $this->form->getState();

$data['user_id'] = auth()->id();

$record = Project::create($data);

$this->form->model($record)->saveRelationships();
}
public function create(): void
{
$data = $this->form->getState();

$data['user_id'] = auth()->id();

$record = Project::create($data);

$this->form->model($record)->saveRelationships();
}
1 Reply
Hasith
Hasith2mo ago
What is the best way to refactor this create method?