How to use LoadMany with withCount

Hello people,

How do I use LoadMany with withCount?

My code looks like this:

      const activity = await Activity.findOrFail(params.id)
      await activity.loadMany({
        type: null,
        'medias.media': null,
        userActivities: (builder) => {
          builder.where('host', true)
            .with('user')
        }
      })

And I need to insert this withCount here:

.withCount('userActivities as count_participates')
1 Like