$ Factory未定义变量

时间:2019-09-09 03:19:24

标签: php laravel-5.6

我正在使用Laravel 5.6,在ProductFactory中出现此错误:未定义变量$ factory

   <?php

use Faker\Generator as Faker;

$factory->define(App\Product::class, function (Faker $faker) {
    return [
        //
    ];
});

1 个答案:

答案 0 :(得分:1)

我通过添加以下行来修复该问题:  /** @var \Illuminate\Database\Eloquent\Factory $factory */

<?php

/** @var \Illuminate\Database\Eloquent\Factory $factory */
use Faker\Generator;
use App\Customer;

$factory->define(Customer::class, function (Generator $faker) {

    return [ 'email' => $faker->unique()->safeEmail ];
});