2014-10-29 88 views
0

你能幫我解決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$ 
+0

你運行'composer update'了嗎? – martindilling 2014-10-29 13:31:01

+0

是的,我發現問題:「require-dev」:{ 「fzaninotto/faker」:「1.3.*@dev」 },必須刪除,它通過自動安裝作曲者完成,否則它不會下載faker或者出錯!而且我還缺少Eloquent :: unguard();在運行函數的第一行。但是,我現在不再出現錯誤,但我也沒有在我的表中獲得任何用戶。這似乎根本不起作用,例如。該表不是創建並填充lorem ipsum用戶。我能做什麼? – Thankyou 2014-10-29 14:19:13

回答

1

我仍然得到同樣的錯誤。我很害怕它沒有加載Fzniotto Faker軟件包。我能做什麼?

在您的shell中,嘗試運行php artisan dump-autoload


運行composer update,然而你卻在你的composer.json中缺少一個逗號;

"require": { 
    "laravel/framework": "4.2.*" 
    "fzaninotto/faker": "1.3.*@dev" 
} 

應該是;

"require": { 
    "laravel/framework": "4.2.*", 
    "fzaninotto/faker": "1.3.*@dev" 
} 

如果您已經有了依賴關係並且錯誤地複製了代碼,請嘗試運行composer dump-autoload

1

是啊,你忘了一個逗號

"require": { 
    "laravel/framework": "4.2.*", 
    "fzaninotto/faker": "1.3.*@dev" 
}, 

然後運行composer update

1

不過,我現在不再得到一個錯誤,但我也不會在我的表中獲取任何用戶。這似乎根本不起作用,例如。該表不是創建並填充lorem ipsum用戶。我能做什麼?

您是否創建了用戶表?

如果不是,你需要;

運行php artisan migrate:make create_users_table

在您的app/database/migrations文件夾中,您將找到新的遷移文件。

構建您的遷移(http://laravel.com/docs/4.2/schema)。

運行php artisan migrate

運行php artisan db:seed

+0

嗨,我有表,但我需要打開遷移,再次保存,然後運行數據庫:種子,然後它工作:)))非常感謝你! – Thankyou 2014-10-29 15:14:32

+1

沒問題,祝你有美好的一天。 – dojs 2014-10-29 19:36:54