Cleaned up the models

This commit is contained in:
Graham Campbell
2015-01-01 18:57:33 +00:00
parent ee2d3bce3b
commit 5937b7b040
9 changed files with 95 additions and 36 deletions

View File

@@ -4,6 +4,11 @@ use Illuminate\Database\Eloquent\Model;
class Setting extends Model
{
/**
* The fillable properties.
*
* @var string[]
*/
protected $fillable = ['name', 'value'];
/**
@@ -12,41 +17,25 @@ class Setting extends Model
* @param string $settingName
* @param bool $checkEnv
*
* @return string
* @return string|null
*/
public static function get($settingName, $checkEnv = true)
{
// Default setting value.
$setting = null;
// First try finding the setting in the database.
try {
$setting = self::whereName($settingName)->first()->value;
} catch (ErrorException $e) {
// If we don't have a setting, check the env (fallback for original version)
if ($checkEnv) {
if (!($setting = getenv(strtoupper($settingName)))) {
return $setting;
$env = getenv(strtoupper($settingName));
if (!$env) {
return $env;
}
} else {
return $setting;
}
return $setting;
}
return $setting;
}
/**
* Throws an Exception.
*
* @param string $setting
*
* @throws \Exception
*
* @return void
*/
public static function unknownSettingException($setting)
{
throw new Exception(sprintf('Unknown setting %s', $setting));
}
}