create(); /** @var array $albums */ $albums = Album::factory(3)->create([ 'artist_id' => $artist->id, ]); // 7-15 songs per albums foreach ($albums as $album) { Song::factory(random_int(7, 15))->create([ 'album_id' => $album->id, 'artist_id' => $artist->id, ]); } } protected static function getNonPublicProperty($object, string $property) // @phpcs:ignore { $reflection = new ReflectionClass($object); $property = $reflection->getProperty($property); $property->setAccessible(true); return $property->getValue($object); } }