Best way to get some data on each request and pass to view


Let’s say we have menu items that are kept in database, these items are displayed on each page, what is the best way getting them and passing to view?


I thought about using a View hook registered after.providersBooted and querying menu items inside, then generating markup and passing, but this will only request items once.
Is there a way better?


You want to fetch the items on each page reload?


Basically yes, because these menu items may be added or edited in management area.
Currently I did it just querying menus in each controller and passing data to view, but this is not really very DRY, so I decided to ask for a better solution…


Then, I suggest using the middleware for that.

async handle ({ view }) {
  const menuItems = // get them from somewhere
  view.share({ menuItems })