php - Larvel5 Global $config var - fetched form db? -



php - Larvel5 Global $config var - fetched form db? -

i have config table holds lots of configuration values, how can create static helper/class available globally on laravel?

for example, have view input:

<input type="text" value="<?= settingshelper::getvalue('my-settings-key'); ?>" />

and off course of study don't want query each time it, 1 query gets configuration values.

any ideas?

you can create this,

class settinghelper { protected $items; public function get($key, $default = null) { if ( empty($this->items)) { $this->loadsettingdata(); } if ( array_key_exists($key, $this->items) ) { homecoming $this->items[$key]; } homecoming value($default); } protected function loadsettingdata() { $this->items = setting::all()->lists('key', 'value'); } }

need bind class in container singleton.

php laravel

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -