create(); $lists = LinkList::factory()->count(10)->create(); $tags = Tag::factory()->count(30)->create(); // Generate links and attach tags to them Link::factory()->count(50)->create()->each(function (Link $link) use ($tags, $lists) { if (random_int(0, 1)) { // Attach a random number of tags to the link $link->tags()->sync($tags->random(random_int(1, 8))->pluck('id')); } if (random_int(0, 1)) { // Attach a random number of tags to the link $link->lists()->sync($lists->random(random_int(1, 2))->pluck('id')); } }); } }