Get the "creator" model to use it in beforeCreate Hook



I’m working on a Picture model. My idea is to save all the pictures of each user on a folder with the user slug name.

In the Picture model I have a “url” field that is 'uploads/user_slug/picturename.jpg

When the user uploads a picture I want to use:


And then in the Picture Model I want to create a before_save hook.

class Picture extends Model {
  static boot () {

    this.addHook('beforeCreate', async (instance) => {
      // Get the User Slug, create the URL and create the Picture.

How can I get the User in the Picture beforeCreate hook?



In the picture create method, you can pass a param let’s say user_id then you can read it from your instance in the before create


Hi @pikitgb.
Thanks for your comment, but I thought there might be a better way. It seems not.