Add additional settings; Use pilot id length from setting
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user