你可以帮我解决这个错误吗?我跑了php artisan db:seed --class=UserTableSeeder
并得到了:
PHP致命错误:
/ Users / I / Laravel / authapp / app / database / seeds中找不到类
'Faker\Factory'
第7行的/UserTableSeeder.php
{
"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的autoload包含它,它也不起作用。我在哪里可以找到错误?
我仍然得到同样的错误。我很害怕它没有加载Fzniotto Faker包。我能做什么?如果我尝试通过下载来包含它,我会得到
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 :(得分: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 :(得分:1)
"require": {
"laravel/framework": "4.2.*",
"fzaninotto/faker": "1.3.*@dev"
},
然后运行composer update
答案 2 :(得分: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
。