Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Position 0 at $index array is not certain to be existing #5927

Open
Ciolo2002 opened this issue Nov 8, 2024 · 1 comment
Open

Position 0 at $index array is not certain to be existing #5927

Ciolo2002 opened this issue Nov 8, 2024 · 1 comment

Comments

@Ciolo2002
Copy link

Laravel version

11.30.0

PHP version

8.3.12

Voyager version

v1.8.0

Database

MySql 8.4

Description

The $index should not contain position 0 as it depens on mysql sorting while getting indexes.

Steps to reproduce

Create a table with more and 3 indexes and try to edit such BREAD, it will crash due to
Undefined array key 0 at /var/www/vendor/tcg/voyager/src/Database/Schema/SchemaManager.php:76

Expected behavior

be certain to have $index[0] or a check to its existance

Screenshots

No response

Additional context

you should use array_values or check if !empty($indexes[0]['type']))

@Ciolo2002
Copy link
Author

Ciolo2002 commented Nov 8, 2024

the problem is in /var/www/vendor/tcg/voyager/src/Database/Schema/SchemaManager.php:76
public static function describeTable($tableName)
{
$columns = Schema::getColumnListing($tableName);

    return collect($columns)->map(function ($column) use ($tableName) {
        $columnDetails = static::getColumnDetails($tableName, $column);
        $indexes = static::getColumnIndexes($tableName, $column);
        if (!empty($indexes) && isset($indexes[1])) {
            $indexes = [$indexes[1]];
        }

        return [
            'field' => $column,
            'type' => $columnDetails['type'],
            'null' => $columnDetails['nullable'],
            'key' => !empty($indexes) ? substr($indexes[0]['type'], 0, 3) : null, //PROBLEM HERE!!!!!!!!!!
            'default' => $columnDetails['default'],
            'extra' => $columnDetails['auto_increment'] ? 'auto_increment' : '',
            'indexes' => $indexes,
        ];
    });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant