你能幫我解決laravel中的這個錯誤嗎?我跑php artisan db:seed --class=UserTableSeeder
,並得到:Fzaninotto Faker安裝包
PHP致命錯誤:
Class
'Faker\Factory'
not found in /Users/I/Laravel/authapp/app/database/seeds /UserTableSeeder.php on line 7
{
"error":{
"type":"Symfony\\Component\\Debug\\Exception \\FatalErrorException",
"message":"Class 'Faker\\Factory' not found",
"file":"\/Users /I\/Laravel\/authapp\/app\/database\/seeds\/UserTableSeeder.php",
"line":7
}
}
我UserTableSeeder.php
<?php
class UserTableSeeder extends Seeder
{
public function run()
{
$faker = Faker\Factory::create();
User::truncate();
foreach(range(1,30) as $index)
{
User::create([
'username' => str_replace('.', '_', $faker->unique()->userName),
'email' => $faker->email,
'password' => 'password',
]);
}
}
}
我composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.2.*",
"fzaninotto/faker": "1.3.*@dev"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable",
"require-dev": {
"fzaninotto/faker": "1.3.*@dev"
},
}
添加逗號後,我仍然得到相同的錯誤,如果我嘗試使用自動加載從github包括它也不起作用。我在哪裏可以查找錯誤?
我仍然得到相同的錯誤。我很害怕它沒有加載Fzniotto Faker軟件包。我能做什麼?如果我嘗試downlaoding它包括包,我得到
PHP Warning: Uncaught exception 'ErrorException' with message 'require_once(../../../vendor/Faker/autoload.php): failed to open stream: No such file or directory' in /Users/stefanieness/Laravel/authapp/app/database/seeds/UserTableSeeder.php:6
Stack trace:
#0 /Users/stefanieness/Laravel/authapp/app/database/seeds/UserTableSeeder.php(6): Illuminate\Exception\Handler->handleError(2, 'require_once(.....', '/Users/stefanie...', 6, Array)
#1 /Users/stefanieness/Laravel/authapp/app/database/seeds/UserTableSeeder.php(6): UserTableSeeder::run()
#2 /Users/stefanieness/Laravel/authapp/vendor/laravel/framework/src/Illuminate/Database/Console/SeedCommand.php(57): UserTableSeeder->run()
#3 /Users/stefanieness/Laravel/authapp/vendor/laravel/framework/src/Illuminate/Console/Command.php(112): Illuminate\Database\Console\SeedCommand->fire()
#4 /Users/stefanieness/Laravel/authapp/vendor/symfony/console/Symfony/Component/Console/Command/Command.php(252): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), O in /Users/stefanieness/Laravel/authapp/app/database/seeds/UserTableSeeder.php on line 6
PHP Fatal error: UserTableSeeder::run(): Failed opening required '../../../vendor/Faker/autoload.php' (include_path='/Users/stefanieness/Laravel/authapp/vendor/phpseclib/phpseclib/phpseclib:.:') in /Users/stefanieness/Laravel/authapp/app/database/seeds/UserTableSeeder.php on line 6
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"UserTableSeeder::run(): Failed opening required '..\/..\/..\/vendor\/Faker\/autoload.php' (include_path='\/Users\/stefanieness\/Laravel\/authapp\/vendor\/phpseclib\/phpseclib\/phpseclib:.:')","file":"\/Users\/stefanieness\/Laravel\/authapp\/app\/database\/seeds\/UserTableSeeder.php","line":6}}SEICCN-3:authapp stefanieness$
你運行'composer update'了嗎? – martindilling 2014-10-29 13:31:01
是的,我發現問題:「require-dev」:{ 「fzaninotto/faker」:「1.3.*@dev」 },必須刪除,它通過自動安裝作曲者完成,否則它不會下載faker或者出錯!而且我還缺少Eloquent :: unguard();在運行函數的第一行。但是,我現在不再出現錯誤,但我也沒有在我的表中獲得任何用戶。這似乎根本不起作用,例如。該表不是創建並填充lorem ipsum用戶。我能做什麼? – Thankyou 2014-10-29 14:19:13