Merge branch 'settings' into dev
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Settings extends Model
|
||||
{
|
||||
protected $table = 'settings';
|
||||
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;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user