laravel Fzaninotto Faker 安装包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26631546/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:20:35  来源:igfitidea点击:

Fzaninotto Faker Install package

phpjsonlaravel

提问by Thankyou

Can you help me with this error in laravel? I ran php artisan db:seed --class=UserTableSeederand got:

你能帮我解决 Laravel 中的这个错误吗?我跑了php artisan db:seed --class=UserTableSeeder,得到:

PHP Fatal error:

PHP 致命错误:

Class 'Faker\Factory'not found in /Users/I/Laravel/authapp/app/database/seeds /UserTableSeeder.php on line 7

'Faker\Factory'在/用户/ I / Laravel / authapp /应用程序/数据库/种子/UserTableSeeder.php未找到第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
}
}

My UserTableSeeder.php

我的 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', 
            ]);  
        }
    }
}  

My composer.json

我的 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"
  },

}

After adding the comma, I still get the same error and If I try to include it using autoload from github it also does not work. Where could I look for the error?

添加逗号后,我仍然遇到相同的错误,如果我尝试使用来自 github 的自动加载来包含它,它也不起作用。我在哪里可以查找错误?

I still get the same error. I am scared that it is not loading the Fzniotto Faker Package. What can I do? If I try to include the package by downlaoding it, I get

我仍然遇到同样的错误。我很害怕它没有加载 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$ 

回答by dojs

I still get the same error. I am scared that it is not loading the Fzniotto Faker Package. What can I do?

我仍然遇到同样的错误。我很害怕它没有加载 Fzniotto Faker 包。我能做什么?

In your shell, try running php artisan dump-autoload.

在您的 shell 中,尝试运行php artisan dump-autoload.



Run composer update, you are however missing a comma in your composer.json;

运行composer update,但是您的 composer.json 中缺少一个逗号;

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

Should be;

应该;

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

If you already have the dependency and copied the code wrong try running composer dump-autoload.

如果您已经拥有依赖项并且错误地复制了代码,请尝试运行composer dump-autoload.

回答by teeyo

Yup, you forgot a comma

是的,你忘记了逗号

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

then run composer update

然后运行 composer update

回答by dojs

However, I now no longer get an error, but I also do not get any users in my table. It seems to be simply not working, eg. the table is not created and filled with lorem ipsum users. What can I do?

但是,我现在不再收到错误消息,但我的表中也没有任何用户。它似乎根本不起作用,例如。该表未创建并填充 lorem ipsum 用户。我能做什么?

Have you created your users table?

您是否创建了用户表?

If not you need to;

如果没有,你需要;

Run php artisan migrate:make create_users_table.

运行php artisan migrate:make create_users_table

In your app/database/migrationsfolder you will find your new migration file.

在您的app/database/migrations文件夹中,您将找到新的迁移文件。

Build your migration (http://laravel.com/docs/4.2/schema).

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

Run php artisan migrate.

运行php artisan migrate

Run php artisan db:seed.

运行php artisan db:seed