{closure}()必须是laravel工厂种子上的Faker \ Generator \ Generator的实例

rob*_*pin 1 factory laravel laravel-seeding

当我使用php artisan db:seed时出现错误?在UserFactory.php第27行中:

Type error: Argument 1 passed to
Illuminate\Database\Eloquent\Factory::{closure}() must be an instance
of Faker\Generator\Generator, instance of Faker\Generator given
Run Code Online (Sandbox Code Playgroud)

Userfactory.php 使用Faker \ Generator作为Faker;

(这是第27行)

$factory->define(App\Models\Admin::class, function (Faker\Generator $faker) {
    static $password;

        return [
            'name' => $faker->name,
            'email' => $faker->safeEmail,
            'password' => $password ?: $password = bcrypt('secret'),
            'remember_token' => str_random(10),
        ];
    });
Run Code Online (Sandbox Code Playgroud)

AdminsTableSeeder.php

public function run()
{
    factory('App\Models\Admin',3)->create([
        'password' => bcrypt('123456')
        ]);
}
Run Code Online (Sandbox Code Playgroud)

DatabaseSeeder.php

public function run()
{
    // $this->call(UsersTableSeeder::class);
    $this->call(AdminsTableSeeder::class);
}
Run Code Online (Sandbox Code Playgroud)

我不知道怎么回事。

rob*_*pin 5

我使用Faker \ Generator作为Faker解决了它;

(this is line 27)
    $factory->define(App\Models\Admin::class, function (Faker $faker) 
Run Code Online (Sandbox Code Playgroud)

这意味着不要function(Faker\Generator $faker)在函数中使用,而应使用function (Faker $faker)

那为我解决了。