-1

When I run php artisan migrate:fresh --seed I get the error:

Target class [DatabaseSeeder] does not exist.

I did the suggestions pointed in this link but not effect the same issue as in laravel 8 with seeding , i has this issue Target class [TableSeeder] does not exist

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.2.5",
        "fideloper/proxy": "^4.2",
        "fruitcake/laravel-cors": "^1.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "laravel/framework": "^8.0",
        "laravel/tinker": "^2.0",
        "laravel/ui": "^3.0"
    },
    "require-dev": {
        "facade/ignition": "^2.3.6",
        "fzaninotto/faker": "^1.9.1",
        "mockery/mockery": "^1.3.1",
        "nunomaduro/collision": "^5.0",
        "phpunit/phpunit": "^9.0"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeders",
            "database/factories"
        ],
        "files": [
            "app/helpers.php"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}

And this is my databaseseeder which is in /database/seeders/

<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        $this->call(UsersSeeder::class);
        $this->call(InstallationSeeder::class);
        $this->call(MaintenanceReasonSeeder::class);
        $this->call(CompanytypesSeeder::class);
        $this->call(LocationTypeSeeder::class);
        $this->call(formTypeseeder::class);
    }
}
Tim Lewis
  • 27,813
  • 13
  • 73
  • 102
PimD1988
  • 307
  • 5
  • 14

1 Answers1

1

You need to remove the entries from the classmap and specify the mapping for Database namespace under psr4 like

{
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        },
        "files": [
            "app/helpers.php"
        ]
    },
}

Then run composer dump-autoload

Donkarnash
  • 12,433
  • 5
  • 26
  • 37
  • It's enough to set `"Database\\": "database/"`. – Tpojka Dec 24 '20 at 06:50
  • 1
    @Tpojka Haha.. you are right - completely missed when moving the `classmap` entries to `psr4` - just moved both entries and updated - silly me. Thanks for pointing out will update the answer – Donkarnash Dec 24 '20 at 07:03
  • Although it is better to do your way heh. Two reasons for that: factories and seeders directories are lower case and don't follow PSR syntax, plus migrations directory consist of classes that are not file name <-> class name equivalents. – Tpojka Dec 24 '20 at 07:07
  • 1
    Hmm...that's why the standard Laravel 8 has two different entries mapping namespace under `psr4` for factories and seeders. Let me update again. – Donkarnash Dec 24 '20 at 07:11