Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions src/Setting/SettingEloquentStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,23 @@ class SettingEloquentStorage implements SettingStorage
*/
protected $settingsCacheKey = 'app_settings';

/**
* Fields to select
*
* @var array
*/
protected $selectionFields = ['val', 'name'];

/**
* {@inheritdoc}
*/
public function all($fresh = false)
{
if ($fresh) {
return $this->modelQuery()->pluck('val', 'name');
}

return Cache::rememberForever($this->getSettingsCacheKey(), function () {
return $this->modelQuery()->pluck('val', 'name');
});
return $fresh
? $this->fullQuery()
: Cache::rememberForever($this->getSettingsCacheKey(), function () {
return $this->fullQuery();
});
}

/**
Expand Down Expand Up @@ -106,7 +111,7 @@ public function flushCache()
*/
protected function getSettingsCacheKey()
{
return $this->settingsCacheKey.'.'.$this->settingsGroupName;
return $this->settingsCacheKey . '.' . $this->settingsGroupName;
}

/**
Expand Down Expand Up @@ -141,4 +146,24 @@ public function group($groupName)

return $this;
}

/**
* Get the query
*
* @return Builder
*/
public function fullQuery()
{
return $this->modelQuery()->pluck($this->getSelectionFields());
}

/**
* Get the to be selected
*
* @return array
*/
public function getSelectionFields()
{
return $this->selectionFields;
}
}