Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions src/Orangehill/Iseed/Iseed.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Composer;
use Illuminate\Support\Facades\Config;
use Doctrine\DBAL\DriverManager;
use Illuminate\Support\Facades\DB;

class Iseed
{
Expand Down Expand Up @@ -425,8 +427,34 @@ public function updateDatabaseSeederRunMethod($className)

public function getAllTableNames()
{
// Depending on your Laravel version, you may use the Doctrine schema manager:
$schema = \DB::connection($this->databaseName)->getDoctrineSchemaManager();
return $schema->listTableNames();
// Use the provided database name, or fallback to Laravel's default connection
$connectionName = $this->databaseName ?? config('database.default');

// Get the Laravel database connection object
$connection = DB::connection($connectionName);

// Get the underlying PDO instance for the Doctrine connection
$pdo = $connection->getPdo();

// Retrieve the database configuration for the selected connection
$config = config("database.connections.{$connectionName}");

// Prepare connection parameters for Doctrine DBAL
$connectionParams = [
'pdo' => $pdo, // Use the active PDO connection from Laravel
'dbname' => $config['database'], // Database name from config
'user' => $config['username'], // DB username from config
'password' => $config['password'], // DB password from config
'driver' => 'pdo_mysql', // Specify MySQL driver for DBAL
];

// Create a Doctrine DBAL connection using the provided params
$doctrineConn = DriverManager::getConnection($connectionParams);

// Get the Doctrine schema manager for retrieving schema details
$schemaManager = $doctrineConn->createSchemaManager();

// Return the list of all table names in the database
return $schemaManager->listTableNames();
}
}