Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code refactoring #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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;
}
}