add setting() helper; fix invalid defaults for mysql in table

This commit is contained in:
Nabeel Shahzad
2017-12-09 21:56:26 -06:00
parent 3a22062cd2
commit f2add8908b
7 changed files with 60 additions and 6 deletions

View File

@@ -35,10 +35,10 @@ class SettingsController extends BaseController
*/
public function update(Setting $setting, Request $request)
{
$/*this->validate($request, Setting::$rules, Setting::$messages);
/*$this->validate($request, Setting::$rules, Setting::$messages);
$this->updateEntry($setting, $request->all());*/
return redirect("/admin/settings");
return redirect('/admin/settings');
}
}

View File

@@ -21,7 +21,7 @@ class Migration extends MigrationBase
try {
DB::table($table)->insert($row);
} catch (Exception $e) {
# setting already exists
# setting already exists, just ignore it
if ($e->getCode() === 23000) {
continue;
}

View File

@@ -4,6 +4,7 @@ namespace App\Providers;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use App\Repositories\SettingRepository;
class AppServiceProvider extends ServiceProvider
@@ -15,6 +16,8 @@ class AppServiceProvider extends ServiceProvider
{
Schema::defaultStringLength(191);
$this->app->bind('setting', SettingRepository::class);
//\VaCentral\VaCentral::setVaCentralUrl(config('phpvms.vacentral_api_url'));
if(!empty(config('phpvms.vacentral_api_key'))) {
\VaCentral\VaCentral::setApiKey(config('phpvms.vacentral_api_key'));

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Repositories;
use App\Models\Setting;
use App\Repositories\Traits\CacheableRepository;
use Prettus\Repository\Contracts\CacheableInterface;
class SettingRepository extends BaseRepository implements CacheableInterface
{
use CacheableRepository;
public function model()
{
return Setting::class;
}
/**
* Get a setting, reading it from the cache
* @param array $key
* @return mixed|void
*/
public function get($key)
{
}
public function set($key, $value)
{
}
}

16
app/Support/helpers.php Normal file
View File

@@ -0,0 +1,16 @@
<?php
/**
* Shortcut for retrieving a setting value
*/
if (!function_exists('setting')) {
function setting($key, $value = null)
{
$settingRepo = app('setting');
if($value === null) {
return $settingRepo->get($key);
} else {
$settingRepo->set($key, $value);
}
}
}