I've been trying to get this to work but it just doesn't work. I have this function where I insert multiple records into different tables at a time and I am using transaction but it won't rollback when one of the query fails.
See example:
private function valBankInvestment($bank, $investment, $investment1, $data){
DB::beginTransaction();
$new_bank = DB::table('bank_accounts')->insert($bank);
$new_inv = Investments::create($investment);
$inv_log = DB::table('investment_logs')->insertGetId($investment1);
$trader = Traders::create($data);
if ($new_bank && $new_inv && $inv_log && $trader) {
DB::commit();
return true;
}
DB::rollBack();
return false;
}
What I want to achieve is that the above function should rollback if any of those queries should fail. Please help me out with this.