Roots Discourse

Question about Controllers


I had a question about controllers. When putting things like ACF fields and such in my controller to access in my templates. Does it hit the database for that acf function only once when the controller is created or is it hitting the database every time I call that method?

Just trying to get a better understanding of how Blade templates work. I want to create some sort of global function to access my main navigation. I have to put it in the header and footer. So I was trying to understand what the most DRY method for that might be using Blade. Thanks!



@paperrobots - not 100% sure without monitoring the queries, but since Controller uses ACF’s functions to fetch the data, and ACF caches any value loaded from the DB, there’s a good chance that the DB will only be queried once.

PS - I’d probably do any necessary logic / data prep for your nav in the App.php controller and then include a menu template partial that consumes that data. You’d include the same partial in both your header and footer if the menu markup is the same in both locations, or use two different partials if the markup differs.