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) 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());*/ $this->updateEntry($setting, $request->all());*/
return redirect("/admin/settings"); return redirect('/admin/settings');
} }
} }

View File

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

View File

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

View File

@ -63,6 +63,9 @@
"bpocallaghan/generators": "5.0.1" "bpocallaghan/generators": "5.0.1"
}, },
"autoload": { "autoload": {
"files": [
"app/Support/helpers.php"
],
"classmap": [ "classmap": [
"database" "database"
], ],

View File

@ -15,11 +15,11 @@ class CreateSettingsTable extends Migration
Schema::create('settings', function (Blueprint $table) { Schema::create('settings', function (Blueprint $table) {
$table->increments('id'); $table->increments('id');
$table->integer('order')->default(1); $table->integer('order')->default(1);
$table->string('name')->default(''); $table->string('name');
$table->string('key'); $table->string('key');
$table->string('value'); $table->string('value');
$table->string('group')->default('general'); $table->string('group')->nullable();
$table->text('type')->default('text'); $table->text('type')->nullable();
$table->text('options')->nullable(); $table->text('options')->nullable();
$table->text('description')->nullable(); $table->text('description')->nullable();
$table->timestamps(); $table->timestamps();