View counter in strapi: With lifecycle hooks? But how to use them?

Thanks,
I did it with controllers:

 async findOne(ctx) {
    const response = await super.findOne(ctx);

    await strapi.query("api::article.article")
      .update({
        where: { id: response.data.id },
        data: { views: parseInt(response.data.attributes.views) + 1 }
      });

    return response;
  },
1 Like