I have created a store method which stores two step-form that saves data to different tables. I want a scenario were if a commit fails for any of the tables it should rollback.
CODE
public function store()
{
try{
$staffrecs = Staffrecord::create([
'staff_id' => '',
'first_name' => $this->state['first_name'],
'middle_name' => $this->state['middle_name'],
'last_name' => $this->state['last_name'],
'designation' => $this->state['designation'],
'grade_level_id' => $this->state['grade_level_id'],
'phone_number' => $this->state['phone_number'],
'email' => $this->state['email'],
'address' => $this->state['address'],
]);
$staffrecs->bankaccount()->create([
'account_number' => $this->state['account_number'],
'account_name' => $this->state['account_name'],
'bank_name' => $this->state['bank_name'],
'sort_code' => $this->state['sort_code'],
]);
return redirect()->route('dashboard');
}catch (\Exception $e)
{
return false;
}
}