Laravel Forge 上的部署未找到 Faker 异常
Deployment on Laravel Forge throwing faker not found Exception
我正在尝试在 Forge 上部署一个 laravel 项目,但出现以下异常:
Symfony\Component\Debug\Exception\FatalErrorException]
Class 'Faker\Factory' not found
我在 composer.json!
的 require-dev 中有 faker 参考
composer.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 包。
如果我遗漏了什么,请告诉我。
有一个明显的冲突可以解释您的问题:
您已将 "fzaninotto/faker"
包添加到 require-dev
部分。
您正在 运行 部署 composer install
命令和 --no-dev
选项,explicitly prohibits 安装 require-dev
中列出的软件包.
所以解决方案是要么将包移动到 require
部分,要么在部署时删除 --no-dev
选项。
这样做
$faker = \Faker\Factory::create();
这样使用
$sub_g->name = $faker->name();
$sub_g->country = $faker->country();
$sub_g->state = $faker->state;
稍后谢谢我。
我正在尝试在 Forge 上部署一个 laravel 项目,但出现以下异常:
Symfony\Component\Debug\Exception\FatalErrorException]
Class 'Faker\Factory' not found
我在 composer.json!
的 require-dev 中有 faker 参考composer.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 包。
如果我遗漏了什么,请告诉我。
有一个明显的冲突可以解释您的问题:
您已将
"fzaninotto/faker"
包添加到require-dev
部分。您正在 运行 部署
composer install
命令和--no-dev
选项,explicitly prohibits 安装require-dev
中列出的软件包.
所以解决方案是要么将包移动到 require
部分,要么在部署时删除 --no-dev
选项。
这样做
$faker = \Faker\Factory::create();
这样使用
$sub_g->name = $faker->name();
$sub_g->country = $faker->country();
$sub_g->state = $faker->state;
稍后谢谢我。