laravel 错误[RuntimeException]无法扫描“数据库/种子”中的类

ivqmmu1c  于 2023-01-18  发布在  其他
关注(0)|答案(2)|浏览(137)

运行 composer 更新时出现问题
其他安装命令也会发生同样的情况
错误:
[RuntimeException]无法扫描"database/seeds"中似乎不是文件或文件夹的类
我该如何解决这个错误?尝试,运行composer安装,它也不工作

{
"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": "^6.3",
    "laravel/framework": "^7.0",
    "laravel/tinker": "^2.0",
    "laravel/ui": "^2.0"
},
"require-dev": {
    "facade/ignition": "^2.0",
    "fzaninotto/faker": "^1.9.1",
    "mockery/mockery": "^1.3.1",
    "nunomaduro/collision": "^4.1",
    "phpunit/phpunit": "^8.5"
},
"config": {
    "optimize-autoloader": true,
    "preferred-install": "dist",
    "sort-packages": true
},
"extra": {
    "laravel": {
        "dont-discover": []
    }
},
"autoload": {
    "psr-4": {
        "App\\": "app/"
    },
    "classmap": [
        "database/seeds",
        "database/factories"
    ]
},
"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"
    ]
}
}
q3aa0525

q3aa05251#

将自动加载的编写器更改为

"autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    }

在Laravel 8中,工厂和种子两个目录都有命名空间,而在Laravel 7中,仍然使用类Map来加载它们。
首先,检查你的类是否使用命名空间,然后使用psr 4autoload,否则你可以使用类Map;

y4ekin9u

y4ekin9u2#

在我的例子中,我在composer.json > autoload > classmap下将"database/seeds"更改为"database/seeders",并解决了这个问题。

"autoload": {
    "psr-4": {
        "App\\": "app/"
    },
    "classmap": [
        "database/seeders",
        "database/factories"
    ]
},

相关问题