classes/Connection.php
public function transaction(callable $closure)
    {
        $this->start();
        try {
            $result = $closure();
        } catch (\Throwable $e) {
            $this->rollback();
            throw $e;
        }
        $this->commit();

        return $result;
    }
public function transaction(callable $closure)
    {
        $this->start();
        try {
            $result = $closure();
        } catch (\Throwable $e) {
            $this->rollback();
            throw $e;
        }
        $this->commit();

        return $result;
    }
public function transaction ( callable $ closure ) { $ this -> start ( ) ; try { $ result = $ closure ( ) ; } catch ( \ Throwable $ e ) { $ this -> rollback ( ) ; throw $ e ; } $ this -> commit ( ) ; return $ result ; }
Run a closure inside a transaction

Begins a transaction before running the closure and commits the
transaction afterwards. When the closure emits an exception or
throwable error, the transaction will be rolled back.

@param callable $closure Closure without required parameters
@return mixed Closure return value
@throws \Throwable Exceptions thrown by the closure
Run a closure inside a transaction