我正在使用Laravel 5.6,在ProductFactory中出现此错误:未定义变量$ factory
<?php
use Faker\Generator as Faker;
$factory->define(App\Product::class, function (Faker $faker) {
return [
//
];
});
答案 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 ];
});