--- /dev/null
+root = true
+
+[*]
+charset = utf-8
+end_of_line = lf
+insert_final_newline = true
+indent_style = space
+indent_size = 4
+trim_trailing_whitespace = true
+
+[*.md]
+trim_trailing_whitespace = false
+
+[*.yml]
+indent_size = 2
"require-dev": {
"backpack/generators": "^1.2"
},
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0-dev"
+ },
+ "laravel": {
+ "providers": [
+ "Cubeist\\Backpack\\ServiceProvider"
+ ]
+ }
+ },
"repositories": [
{
"type": "composer",
--- /dev/null
+<?php
+
+namespace Cubist\Backpack;
+
+use Backpack\Settings\app\Models\Template as Setting;
+use Config;
+use Illuminate\Routing\Router;
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Support\ServiceProvider;
+use Route;
+
+class CubistBackpackServiceProvider extends ServiceProvider
+{
+ /**
+ * Indicates if loading of the provider is deferred.
+ *
+ * @var bool
+ */
+ protected $defer = false;
+
+ /**
+ * Where the route file lives, both inside the package and in the app (if overwritten).
+ *
+ * @var string
+ */
+ public $routeFilePath = '/routes/cubist/backpack/settings.php';
+
+ /**
+ * Perform post-registration booting of services.
+ *
+ * @return void
+ */
+ public function boot()
+ {
+ // define the routes for the application
+ $this->setupRoutes($this->app->router);
+
+// // only use the Settings package if the Settings table is present in the database
+// if (!\App::runningInConsole() && count(Schema::getColumnListing('settings'))) {
+// // get all settings from the database
+// $settings = Setting::all();
+//
+// // bind all settings to the Laravel config, so you can call them like
+// // Config::get('settings.contact_email')
+// foreach ($settings as $key => $setting) {
+// Config::set('settings.' . $setting->key, $setting->value);
+// }
+// }
+ // publish the migrations and seeds
+ $this->publishes([__DIR__ . '/database/migrations/' => database_path('migrations')], 'migrations');
+
+ // publish translation files
+ //$this->publishes([__DIR__ . '/resources/lang' => resource_path('lang/vendor/backpack')], 'lang');
+ }
+
+ /**
+ * Define the routes for the application.
+ *
+ * @param \Illuminate\Routing\Router $router
+ *
+ * @return void
+ */
+ public function setupRoutes(Router $router)
+ {
+ // by default, use the routes file provided in vendor
+ $routeFilePathInUse = __DIR__ . $this->routeFilePath;
+
+ // but if there's a file with the same name in routes/backpack, use that one
+ if (file_exists(base_path() . $this->routeFilePath)) {
+ $routeFilePathInUse = base_path() . $this->routeFilePath;
+ }
+
+ $this->loadRoutesFrom($routeFilePathInUse);
+ }
+
+ /**
+ * Register any package services.
+ *
+ * @return void
+ */
+ public function register()
+ {
+ $this->app->bind('settings', function ($app) {
+ return new Settings($app);
+ });
+
+ // register their aliases
+ $loader = \Illuminate\Foundation\AliasLoader::getInstance();
+ $loader->alias('Setting', \Backpack\Settings\app\Models\Template::class);
+ }
+}
--- /dev/null
+<?php
+
+namespace Cubist\Backpack\app\Http\Controllers;
+
+use Backpack\CRUD\app\Http\Controllers\CrudController;
+// VALIDATION
+use Cubist\Backpack\app\Http\Requests\TemplateRequest as StoreRequest;
+use Cubist\Backpack\app\Http\Requests\TemplateRequest as UpdateRequest;
+
+class TemplateCrudController extends CrudController
+{
+ public function setup()
+ {
+ parent::setup();
+
+ $this->crud->setModel("Cubist\Backpack\app\Models\Setting");
+ $this->crud->setEntityNameStrings(trans('backpack::settings.setting_singular'), trans('backpack::settings.setting_plural'));
+ $this->crud->setRoute(backpack_url('setting'));
+ $this->crud->addClause('where', 'active', 1);
+ $this->crud->denyAccess(['create', 'delete']);
+ $this->crud->setColumns([
+ [
+ 'name' => 'name',
+ 'label' => trans('backpack::settings.name'),
+ ],
+ [
+ 'name' => 'value',
+ 'label' => trans('backpack::settings.value'),
+ ],
+ [
+ 'name' => 'description',
+ 'label' => trans('backpack::settings.description'),
+ ],
+ ]);
+ $this->crud->addField([
+ 'name' => 'name',
+ 'label' => trans('backpack::settings.name'),
+ 'type' => 'text',
+ 'attributes' => [
+ 'disabled' => 'disabled',
+ ],
+ ]);
+ }
+
+ /**
+ * Display all rows in the database for this entity.
+ * This overwrites the default CrudController behaviour:
+ * - instead of showing all entries, only show the "active" ones.
+ *
+ * @return Response
+ */
+ public function index()
+ {
+ return parent::index();
+ }
+
+ public function store(StoreRequest $request)
+ {
+ return parent::storeCrud();
+ }
+
+ /**
+ * Show the form for editing the specified resource.
+ *
+ * @param int $id
+ *
+ * @return Response
+ */
+ public function edit($id)
+ {
+ $this->crud->hasAccessOrFail('update');
+
+ $this->data['entry'] = $this->crud->getEntry($id);
+ $this->crud->addField(json_decode($this->data['entry']->field, true)); // <---- this is where it's different
+ $this->data['crud'] = $this->crud;
+ $this->data['saveAction'] = $this->getSaveAction();
+ $this->data['fields'] = $this->crud->getUpdateFields($id);
+ $this->data['title'] = trans('backpack::crud.edit') . ' ' . $this->crud->entity_name;
+
+ $this->data['id'] = $id;
+
+ // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
+ return view($this->crud->getEditView(), $this->data);
+ }
+
+ public function update(UpdateRequest $request)
+ {
+ return parent::updateCrud();
+ }
+}
--- /dev/null
+<?php
+
+namespace Cubist\Backpack\app\Http\Requests;
+
+use Illuminate\Foundation\Http\FormRequest;
+
+class TemplateRequest extends FormRequest
+{
+ /**
+ * Determine if the user is authorized to make this request.
+ *
+ * @return bool
+ */
+ public function authorize()
+ {
+ // only allow updates if the user is logged in
+ return backpack_auth()->check();
+ }
+
+ /**
+ * Get the validation rules that apply to the request.
+ *
+ * @return array
+ */
+ public function rules()
+ {
+ return [
+ // 'key' => 'required|min:3|max:255',
+ // 'name' => 'required|min:3|max:255',
+ // 'field' => 'required'
+ ];
+ }
+}
--- /dev/null
+<?php
+
+namespace Backpack\Settings\app\Models;
+
+use Backpack\CRUD\CrudTrait;
+use Config;
+use Illuminate\Database\Eloquent\Model;
+
+class Template extends Model
+{
+ use CrudTrait;
+
+ protected $table = 'cubist_templates';
+ protected $fillable = ['value'];
+
+ /**
+ * Grab a setting value from the database.
+ *
+ * @param string $key The setting key, as defined in the key db column
+ *
+ * @return string The setting value.
+ */
+ public static function get($key)
+ {
+ $setting = new self();
+ $entry = $setting->where('key', $key)->first();
+
+ if (!$entry) {
+ return;
+ }
+
+ return $entry->value;
+ }
+
+ /**
+ * Update a setting's value.
+ *
+ * @param string $key The setting key, as defined in the key db column
+ * @param string $value The new value.
+ */
+ public static function set($key, $value = null)
+ {
+ $prefixed_key = 'settings.'.$key;
+ $setting = new self();
+ $entry = $setting->where('key', $key)->firstOrFail();
+
+ // update the value in the database
+ $entry->value = $value;
+ $entry->saveOrFail();
+
+ // update the value in the session
+ Config::set($prefixed_key, $value);
+
+ if (Config::get($prefixed_key) == $value) {
+ return true;
+ }
+
+ return false;
+ }
+}
--- /dev/null
+<?php
+
+/*
+|--------------------------------------------------------------------------
+| Backpack\Settings Routes
+|--------------------------------------------------------------------------
+|
+| This file is where you may define all of the routes that are
+| handled by the Backpack\Settings package.
+|
+*/
+
+Route::group([
+ 'namespace' => 'Cubist\Backpack\app\Http\Controllers',
+ 'prefix' => config('backpack.base.route_prefix', 'admin'),
+ 'middleware' => ['web', backpack_middleware()],
+], function () {
+ CRUD::resource('template', 'TemplateCrudController');
+});