Undefined index: name error in composer [How to Solve]

I made this mistake when:

Laravel version 5.8, need to introduce tcpdf, in the run

composer require tecnickcom/tcpdf

I found two answers, both of which were caused by the composer upgrade, but I don’t remember that I was promoted. I learned from one of the methods and successfully introduced the tcpdf extension. Now I integrate the two methods:

1. Change the source code

Positioning error:

vendor/laravel/framework/src/Illuminate/Foundation/PackageManifest.php

122 line prompt does not have the key name, according to the code prompt to find

/vendor/laravel/framework/src/Illuminate/Support/Collection.php

Of   Mapwithkeys method. Add a compatible method to cover the original method

 public function mapWithKeys(callable $callback)
    {
        $result = [];
        $item = $this->items;
        if(isset($item['packages'])){
            $item = $item['packages'];
        }
        foreach ($item as $key => $value) {
            $assoc = $callback($value, $key);
 
            foreach ($assoc as $mapKey => $mapValue) {
                $result[$mapKey] = $mapValue;
            }
        }
 
        return new static($result);
    }

2. Composer level

# composer Downgrade (if you can't downgrade, you can try to run with root privileges)
composer self-update --1
 
# Re-install and It's Done!!!
composer install 

The above two methods are effective

Read More: