I have a seeder function that run factory like this
Product::factory()
->count(100)
->state(new Sequence(
fn($sequence) => ['age_group_marketplace_id' => $ageGroup->random()]
))
->has(
Media::factory(5)
->state(new Sequence(...self::IMAGE_LIST))
->state(new Sequence(
fn ($sequence) => ['order_column' => $sequence->index]
))
)
->create();
basically, this will create 100 product that have 5 media. But the problem is the $sequence->index will not reset to 0 after 5 media is created for the product. it will just continue until the 499
I expect it will get the index of 0, 1, 2, 3, 4 and then reset to 0 again
You can try to do like this,
I have assumed the
Mediamodel to have aproduct_idforeign key. You can change it to something that your code needs.This has worked for me.