laravel db transaction return value code example
Example 1: laravel db transaction
DB::beginTransaction();
try {
DB::insert(...);
DB::insert(...);
DB::insert(...);
DB::commit();
// all good
} catch (\Exception $e) {
DB::rollback();
// something went wrong
}
Example 2: how to return variable from transaction Laravel
$result = null;
DB::transaction(function () use(&$result) {
// logic here
$result = someGetResult();
});
if ($result != null) {
}