Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have an app with laravel 7, and i upgrade composer 1.10 to composer 2.0, and i have this problem:

Illuminate\Contracts\Container\BindingResolutionException Target class [DatabaseSeeder] does not exist. at vendor/laravel/framework/src/Illuminate/Container/Container.php:807 804| try { 805| $reflector = new ReflectionClass($concrete); 806| } catch (ReflectionException $e) { > 807| throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e); 808| } 810| // If the type is not instantiable, the developer is attempting to resolve 811| // an abstract type such as an Interface or Abstract Class and there is +37 vendor frames 38 artisan:37 Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

I tried many solution (even for Laravel 8 ...) without success.

Here is the autoload of the composer.json

        "psr-4": {
            "App\\": "app/",
            "DatabaseSeeder\\": "database/seeds"
        "files": [
            "app/helpers.php"

Thx !

Here is what I just found: When I add in the composer.json :

  "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories",
            "Database\\Seeds\\": "database/seeds",
            "DatabaseSeeder\\": "database/seeds/",

and that I modify line 84 of SeedCommand.php 'src/vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeedCommand.php', it work !!!

$class = $this->laravel->make($this->input->getOption('class'));
$class = $this->laravel->make('Database\\Seeds\\DatabaseSeeder');

But this is absolutely not maintainable... So the problem is, there is a problem when DatabaseSeeder is set.

6An idea ?

I found the solution: Laravel documention : https://laravel.com/docs/7.x/seeding#introduction

All seed classes are stored in the database/seeds directory.... By default, a DatabaseSeeder class is defined for you.

This folder is not compatible with the PSR-4, so you have to use the classmap in the composer.json with Laravel 7.

It is therefore also necessary to remove the namespaces in the files of seeds.

Here is my composer json:

"autoload": {
        "psr-4": {
            "App\\": "app/",
        "classmap": [
            "database/seeds",
            "database/factories"
        "files": [
            "app/helpers.php"

I solved it as follows:

  • I followed what the documentation said regarding Sedeers and factories
  • I ran composer dump-autoload
  • Update composer to version 2
  • Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.