public function rollback(CapsuleInterface $capsule = null): ?MigrationInterface
    {
        if (!$this->isConfigured()) {
            throw new MigrationException("Unable to run migration, Migrator not configured");
        }

        /** @var MigrationInterface $migration */
        foreach (array_reverse($this->getMigrations()) as $migration) {
            if ($migration->getState()->getStatus() != State::STATUS_EXECUTED) {
                continue;
            }

            $capsule = $capsule ?? new Capsule($this->dbal->database($migration->getDatabase()));
            $capsule->getDatabase()->transaction(function () use ($migration, $capsule) {
                $migration->withCapsule($capsule)->down();
            });

            $this->migrationTable($migration->getDatabase())->delete([
                'migration' => $migration->getState()->getName()
            ])->run();

            return $migration->withState($this->resolveState($migration));
        }

        return null;
    }
public function rollback(CapsuleInterface $capsule = null): ?MigrationInterface
    {
        if (!$this->isConfigured()) {
            throw new MigrationException("Unable to run migration, Migrator not configured");
        }

        /** @var MigrationInterface $migration */
        foreach (array_reverse($this->getMigrations()) as $migration) {
            if ($migration->getState()->getStatus() != State::STATUS_EXECUTED) {
                continue;
            }

            $capsule = $capsule ?? new Capsule($this->dbal->database($migration->getDatabase()));
            $capsule->getDatabase()->transaction(function () use ($migration, $capsule) {
                $migration->withCapsule($capsule)->down();
            });

            $this->migrationTable($migration->getDatabase())->delete([
                'migration' => $migration->getState()->getName()
            ])->run();

            return $migration->withState($this->resolveState($migration));
        }

        return null;
    }
public function rollback ( CapsuleInterface $ capsule = null ) : ? MigrationInterface { if ( ! $ this -> isConfigured ( ) ) { throw new MigrationException ( "Unable to run migration, Migrator not configured" ) ; } /** @var MigrationInterface $migration */ foreach ( array_reverse ( $ this -> getMigrations ( ) ) as $ migration ) { if ( $ migration -> getState ( ) -> getStatus ( ) != State :: STATUS_EXECUTED ) { continue ; } $ capsule = $ capsule ?? new Capsule ( $ this -> dbal -> database ( $ migration -> getDatabase ( ) ) ) ; $ capsule -> getDatabase ( ) -> transaction ( function ( ) use ( $ migration , $ capsule ) { $ migration -> withCapsule ( $ capsule ) -> down ( ) ; } ) ; $ this -> migrationTable ( $ migration -> getDatabase ( ) ) -> delete ( [ 'migration' => $ migration -> getState ( ) -> getName ( ) ] ) -> run ( ) ; return $ migration -> withState ( $ this -> resolveState ( $ migration ) ) ; } return null ; }
Rollback last migration and return it's instance.

@param CapsuleInterface $capsule
@return null|MigrationInterface

@throws \Throwable
Rollback last migration and return it s instance .