InfyOm\Generator\Utils\TableFieldsGenerator::getPrimaryKeyFromTable PHP Method

getPrimaryKeyFromTable() public static method

public static getPrimaryKeyFromTable ( string $tableName ) : string | null
$tableName string
return string | null The column name of the (simple) primary key
    public static function getPrimaryKeyFromTable($tableName)
    {
        $schema = DB::getDoctrineSchemaManager();
        $indexes = collect($schema->listTableIndexes($tableName));
        $primaryKey = $indexes->first(function ($i, $index) {
            return $index->isPrimary() && 1 === count($index->getColumns());
        });
        return !empty($primaryKey) ? $primaryKey->getColumns()[0] : null;
    }