59 lines
1.2 KiB
PHP
59 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Helpers;
|
|
|
|
use App\Configuration;
|
|
|
|
class ConfigHelper
|
|
{
|
|
public function allowedDateFormats()
|
|
{
|
|
return [
|
|
'Y-m-d - H:i',
|
|
'd/m/Y - H:i',
|
|
'm/d/Y - H:i',
|
|
'jS F Y - H:i',
|
|
];
|
|
}
|
|
|
|
public function defaults()
|
|
{
|
|
return array(
|
|
'app_name' => trans('global.app_name'),
|
|
'date_format' => $this->allowedDateFormats()[0]
|
|
);
|
|
}
|
|
|
|
public function get($key, $defaultIfUnset = true)
|
|
{
|
|
$config = Configuration::where('key', $key)->first();
|
|
|
|
return (is_null($config) ? $this->defaults()[$key] : $config->value);
|
|
}
|
|
|
|
public function getAll()
|
|
{
|
|
$results = array();
|
|
|
|
foreach (Configuration::all() as $config)
|
|
{
|
|
$results[$config->key] = $config->value;
|
|
}
|
|
|
|
return $results;
|
|
}
|
|
|
|
public function getOrCreateModel($key)
|
|
{
|
|
$config = Configuration::where('key', $key)->first();
|
|
if (is_null($config) || $config === false)
|
|
{
|
|
$config = new Configuration();
|
|
$config->key = $key;
|
|
$config->value = '';
|
|
$config->save();
|
|
}
|
|
|
|
return $config;
|
|
}
|
|
} |