<?phpnamespaceIlluminate\Foundation\Testing;traitDatabaseTransactions{/** * Handle database transactions on the specified connections. * * @return void */publicfunctionbeginDatabaseTransaction(){$database=$this->app->make('db');foreach($this->connectionsToTransact()as$name){$database->connection($name)->beginTransaction();}$this->beforeApplicationDestroyed(function()use($database){foreach($this->connectionsToTransact()as$name){$database->connection($name)->rollBack();}});}/** * The database connections that should have transactions. * * @return array */protectedfunctionconnectionsToTransact(){returnproperty_exists($this,'connectionsToTransact')?$this->connectionsToTransact:[null];}}