Reload Data after Creating or Updating general Config data


#1

Hi folks

I wrote a provider wich adds some general config data from database to a View.global so i can use this data everywhere in my templates. The problem is, if i update my general configs, the displayed content dont gets updated. Is there a way to reload this provider or will he only loaded once? Here is my code from the provider file:

const { ServiceProvider } = require('@adonisjs/fold')

class SettingsProvider extends ServiceProvider {
  async boot () {
    const View = use('View')
    const Setting = use('App/Models/Setting')
    const settings = await Setting.query().first()

    View.global('globals', () => {
      if(settings) {
        return settings.toJSON()
      }
    })
  }
}

module.exports = SettingsProvider

And those are the edge snippets i use in my templates:

{{ globals().country }}
{{ globals().company }}
etc

#2

Ok, i found a solution. I wrote a middleware wich fires on every route change and so my data will be updated. you can close this post. thx