thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.8k stars 2.67k forks source link

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

Open Ciolo2002 opened 5 days ago

Ciolo2002 commented 5 days ago

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 commented 5 days ago

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,
        ];
    });
}