ci['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 */ protected function connectionsToTransact() { return property_exists($this, 'connectionsToTransact') ? $this->connectionsToTransact : [null]; } }