Add additional settings; Use pilot id length from setting

This commit is contained in:
Nabeel Shahzad
2017-12-12 12:43:58 -06:00
parent 695900a008
commit e05976a982
12 changed files with 82 additions and 45 deletions

View File

@@ -2,9 +2,11 @@
namespace App\Repositories;
use Illuminate\Support\Carbon;
use Prettus\Repository\Contracts\CacheableInterface;
use App\Models\Setting;
use App\Repositories\Traits\CacheableRepository;
use Prettus\Repository\Contracts\CacheableInterface;
class SettingRepository extends BaseRepository implements CacheableInterface
{
@@ -16,17 +18,44 @@ class SettingRepository extends BaseRepository implements CacheableInterface
}
/**
* Get a setting, reading it from the cache
* @param array $key
* @return mixed|void
* Get a setting, reading it from the cache possibly
* @param string $key
* @return mixed
*/
public function get($key)
public function retrieve($key)
{
$key = strtolower($key);
$setting = $this->findWhere(['key' => $key], ['type', 'value'])->first();
if(!$setting) {
return null;
}
# cast some types
switch($setting->type) {
case 'bool':
case 'boolean':
return (bool) $setting->value;
break;
case 'date':
return Carbon::parse($setting->value);
break;
case 'int':
case 'integer':
return (int) $setting->value;
break;
default:
return $setting->value;
}
}
public function set($key, $value)
public function store($key, $value)
{
$setting = $this->findWhere(['key' => $key], ['id'])->first();
if (!$setting) {
return null;
}
$this->update(['value' => $value], $setting->id);
}
}