在编写测试时,我正在使用工厂创建模型,$recipe = factory(Recipe::class)->create()
但是每次创建配方时都会运行并添加关系的回调RecipeFactory
。afterCreating
有没有办法跳过这个回调?我不希望创建任何关系。
RecipeFactory.phpafterCreating
回调
$factory->afterCreating(Recipe::class, function ($recipe, Faker $faker) {
$ingredients = factory(Ingredient::class, 3)->create();
$recipe->ingredients()->saveMany($ingredients);
});