FEATURE: add automacally loaded settings into all views

This commit is contained in:
Michal Kváček
2016-03-14 00:47:06 +01:00
parent 0313a1239f
commit 2a6672934d
2 changed files with 68 additions and 22 deletions
+31
View File
@@ -10,11 +10,42 @@ class Settings extends Model
public $timestamps = false;
protected $fillable = ['key', 'value'];
/**
* Load all settings
*
* @return \stdClass
*/
public function getAll()
{
$settings = Settings::select(['key', 'value'])
->get();
return $this->returnPairs($settings);
}
/**
* Load only config for views
*
* @return \stdClass
*/
public function getForView()
{
$settings = Settings::select(['key', 'value'])
->where('load_into_views', 1)
->get();
return $this->returnPairs($settings);
}
/**
* From pair <key, value> create object key => value
*
* @param $settings
*
* @return \stdClass
*/
private function returnPairs($settings)
{
$data = new \stdClass();
foreach ($settings as $conf) {
$data->{$conf->key} = $conf->value;