Hooks Not working


My Model

'use strict'

const Model = use('Model')

class Service extends Model {
  static get table() {
    return 'services'

  static boot() {
    this.addHook('afterCreate', async (serviceIstance) => {
      console.log(serviceIstance)//It never runs

module.exports = Service

My Controller

let service = await Database

I am using postgres as a database.
And records are effectively created in the database, but the hooks are not executed.

Do you have to do some additional configuration to make them work?

I appreciate your help


Hey @antojsh! :wave:

Hooks are defined in the model scope, in your code you are using the Database Service that don’t use the Model.

const service = await Service.create(dataToSave)