Skip to content

Commit

Permalink
add setting() helper; fix invalid defaults for mysql in table
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelio committed Dec 10, 2017
1 parent 3a22062 commit f2add89
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/Admin/SettingsController.php
Expand Up @@ -35,10 +35,10 @@ public function index()
*/
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');
}

}
2 changes: 1 addition & 1 deletion app/Models/Migrations/Migration.php
Expand Up @@ -21,7 +21,7 @@ public function addData($table, $rows)
try {
DB::table($table)->insert($row);
} catch (Exception $e) {
# setting already exists
# setting already exists, just ignore it
if ($e->getCode() === 23000) {
continue;
}
Expand Down
3 changes: 3 additions & 0 deletions app/Providers/AppServiceProvider.php
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use App\Repositories\SettingRepository;


class AppServiceProvider extends ServiceProvider
Expand All @@ -15,6 +16,8 @@ public function boot()
{
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'));
Expand Down
32 changes: 32 additions & 0 deletions app/Repositories/SettingRepository.php
@@ -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 changes: 16 additions & 0 deletions app/Support/helpers.php
@@ -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);
}
}
}
3 changes: 3 additions & 0 deletions composer.json
Expand Up @@ -63,6 +63,9 @@
"bpocallaghan/generators": "5.0.1"
},
"autoload": {
"files": [
"app/Support/helpers.php"
],
"classmap": [
"database"
],
Expand Down
Expand Up @@ -15,11 +15,11 @@ public function up()
Schema::create('settings', function (Blueprint $table) {
$table->increments('id');
$table->integer('order')->default(1);
$table->string('name')->default('');
$table->string('name');
$table->string('key');
$table->string('value');
$table->string('group')->default('general');
$table->text('type')->default('text');
$table->string('group')->nullable();
$table->text('type')->nullable();
$table->text('options')->nullable();
$table->text('description')->nullable();
$table->timestamps();
Expand Down

0 comments on commit f2add89

Please sign in to comment.