lundi 7 décembre 2020

Laravel factory create without calling afterCreating callback

While writing tests I'm creating a model using factory $recipe = factory(Recipe::class)->create() but the RecipeFactory has afterCreating callback that runs and adds relations every time I create a recipe.

Is there a way to skip this callback? I don't want any relations to be created.

RecipeFactory.php afterCreating callback

$factory->afterCreating(Recipe::class, function ($recipe, Faker $faker) {
    $ingredients = factory(Ingredient::class, 3)->create();
    $recipe->ingredients()->saveMany($ingredients);
});


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire