Convert raw usage of the session model to the repository

This commit is contained in:
Graham Campbell
2015-12-23 15:19:09 +00:00
parent 4718d07561
commit 94ffa5462f
3 changed files with 21 additions and 21 deletions

View File

@@ -51,12 +51,10 @@ class Repository
*/
public function get($name, $default = null)
{
// if we've not loaded the settings, load them now
if (!$this->settings) {
$this->settings = $this->model->all()->lists('value', 'name');
}
// if the setting exists and is not blank, return it
if (!empty($this->settings[$name])) {
return $this->settings[$name];
}
@@ -67,19 +65,25 @@ class Repository
/**
* Creates or updates a setting value.
*
* @param string $name
* @param string $value
* @param string $name
* @param string|null $value
*
* @return void
*/
public function set($name, $value)
{
// save the change to the db
$this->model->updateOrCreate(compact('name'), compact('value'));
if ($value === null) {
$this->model->where('name', $name)->delete();
// if we've loaded the settings, persist this change
if ($this->settings) {
$this->settings[$name] = $value;
if ($this->settings && isset($this->settings[$name])) {
unset($this->settings[$name]);
}
} else {
$this->model->updateOrCreate(compact('name'), compact('value'));
if ($this->settings) {
$this->settings[$name] = $value;
}
}
}
}