7

我正在尝试在 forge 上部署一个 laravel 项目,但出现以下异常:

Symfony\Component\Debug\Exception\FatalErrorException]  
Class 'Faker\Factory' not found     

我在composer.json 的require-dev 中有faker 参考!

作曲家.json 文件

{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
    "php": ">=5.5.9",
    "laravel/framework": "5.1.*",
    "tymon/jwt-auth": "0.5.*",
    "dingo/api": "1.0.x@dev"
},
"require-dev": {
    "fzaninotto/faker": "~1.5",
    "mockery/mockery": "0.9.*",
    "phpunit/phpunit": "~4.0",
    "phpspec/phpspec": "~2.1",
    "laracasts/testdummy": "1.*",
    "laracasts/generators": "^1.1"
},
"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\\": "app/"
    }
},
"autoload-dev": {
    "classmap": [
        "tests/TestCase.php"
    ]
},
"scripts": {
    "post-install-cmd": [
        "php artisan clear-compiled",
        "php artisan optimize"
    ],
    "pre-update-cmd": [
        "php artisan clear-compiled"
    ],
    "post-update-cmd": [
        "php artisan optimize"
    ],
    "post-root-package-install": [
        "php -r \"copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ]
},
"config": {
    "preferred-install": "dist"
}

}

Forge 中的部署脚本:

git pull origin master 
composer install --no-interaction --no-dev --prefer-dist
php artisan migrate --force
php artisan db:seed --class="StaticDataSeeder"

我能够毫无问题地在本地部署相同的项目,并且 forge 上的 composer update 也成功运行,我可以看到 faker 包被下载。

如果我遗漏了什么,请告诉我。

4

2 回答 2

26

有一个明显的冲突可以解释您的问题:

  1. 您已将"fzaninotto/faker"包添加到该require-dev部分。

  2. 您正在使用选项运行部署composer install命令,该--no-dev选项明确禁止安装require-dev.

因此解决方案是将包移动到该部分或在部署时require删除该选项。--no-dev

于 2015-09-26T20:37:01.927 回答
0

这样做

$faker = \Faker\Factory::create();

像这样的使用

$sub_g->name = $faker->name();
    $sub_g->country = $faker->country();
    $sub_g->state = $faker->state;

晚点再谢我。

于 2022-02-23T09:16:46.833 回答