src/Concerns/RefreshDatabase.php
public function beginDatabaseTransaction()
    {
        $database = $this->app->make('db');

        foreach ($this->connectionsToTransact() as $name) {
            $connection = $database->connection($name);
            $dispatcher = $connection->getEventDispatcher();

            $connection->unsetEventDispatcher();
            $connection->beginTransaction();
            $connection->setEventDispatcher($dispatcher);
        }

        $this->beforeApplicationDestroyed(function () use ($database) {
            foreach ($this->connectionsToTransact() as $name) {
                $connection = $database->connection($name);
                $dispatcher = $connection->getEventDispatcher();

                $connection->unsetEventDispatcher();
                $connection->rollback();
                $connection->setEventDispatcher($dispatcher);
                $connection->disconnect();
            }
        });
    }
public function beginDatabaseTransaction()
    {
        $database = $this->app->make('db');

        foreach ($this->connectionsToTransact() as $name) {
            $connection = $database->connection($name);
            $dispatcher = $connection->getEventDispatcher();

            $connection->unsetEventDispatcher();
            $connection->beginTransaction();
            $connection->setEventDispatcher($dispatcher);
        }

        $this->beforeApplicationDestroyed(function () use ($database) {
            foreach ($this->connectionsToTransact() as $name) {
                $connection = $database->connection($name);
                $dispatcher = $connection->getEventDispatcher();

                $connection->unsetEventDispatcher();
                $connection->rollback();
                $connection->setEventDispatcher($dispatcher);
                $connection->disconnect();
            }
        });
    }
public function beginDatabaseTransaction ( ) { $ database = $ this -> app -> make ( 'db' ) ; foreach ( $ this -> connectionsToTransact ( ) as $ name ) { $ connection = $ database -> connection ( $ name ) ; $ dispatcher = $ connection -> getEventDispatcher ( ) ; $ connection -> unsetEventDispatcher ( ) ; $ connection -> beginTransaction ( ) ; $ connection -> setEventDispatcher ( $ dispatcher ) ; } $ this -> beforeApplicationDestroyed ( function ( ) use ( $ database ) { foreach ( $ this -> connectionsToTransact ( ) as $ name ) { $ connection = $ database -> connection ( $ name ) ; $ dispatcher = $ connection -> getEventDispatcher ( ) ; $ connection -> unsetEventDispatcher ( ) ; $ connection -> rollback ( ) ; $ connection -> setEventDispatcher ( $ dispatcher ) ; $ connection -> disconnect ( ) ; } } ) ; }
Begin a database transaction on the testing database.

@return void
Begin a database transaction on the testing database .