我无法在 Laravel Tinker 中使用模型工厂。
//ItemFactory.php
class ItemFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Item::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->name,
'slug' => $this->faker->slug(5, true),
'code' => $this->faker->words(5, true),
'description' => $this->faker->sentence,
'price' => $this->faker->randomNumber(1000, 10000),
'size' => $this->faker->randomElement(['Small', 'Medium', 'Large',]),
];
}
}
修补匠内部
>>> factory(App\Item::class)->create();
它给我一个错误:
PHP 致命错误:在第 1 行的 Psy Shell 代码中调用未定义的函数 factory()