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
Post a Comment