Create multiple records on relationship with a factory

Posted 6 months ago by fabricecw

I try to test a morphMany relationship:

/** @test */
    public function it_has_packagings()
    {
        $variant = factory(Variant::class)->create();

        $variant->packagings()->create(factory(Packaging::class, 10)->raw());

        $this->assertCount(10, $variant->packagings);
    }

But the factory outputs the records inside an array. What's the best way to create multiple records on a relation?

Please sign in or create an account to participate in this conversation.