// Config::set('settings.' . $setting->key, $setting->value);
// }
// }
- // publish the migrations and seeds
- $this->publishes([__DIR__ . '/database/migrations/' => database_path('migrations')], 'migrations');
-
$this->loadTranslationsFrom(__DIR__ . '/resources/lang', 'cubist_back');
-
- // publish translation files
- $this->publishes([__DIR__ . '/resources/lang' => resource_path('lang/vendor/cubist_back')], 'lang');
+ $this->loadMigrationsFrom(__DIR__ . '/database/migrations');
}
/**
$this->crud->setModel("Cubist\Backpack\app\Models\Template");
$this->crud->setEntityNameStrings(trans('cubist_back::templates.template_singular'), trans('cubist_back::templates.template_plural'));
$this->crud->setRoute(backpack_url('template'));
- $this->crud->addClause('where', 'active', 1);
- $this->crud->denyAccess(['create', 'delete']);
$this->crud->setColumns([
[
'name' => 'name',
'label' => trans('cubist_back::templates.name'),
'type' => 'text',
]);
- }
+ $this->crud->addField([
+ 'name' => 'description',
+ 'label' => trans('cubist_back::templates.description'),
+ 'type' => 'textarea',
+ ]);
+ $this->crud->addField([
+ 'name' => 'parent',
+ 'label' => trans('cubist_back::templates.parent'),
+ 'type' => 'select',
+ 'entity' => 'parent',
+ 'attribute' => 'name',
+ 'model' => 'Cubist\Backpack\app\Models\Template',
+ ]);
+ $this->crud->addField([
+ 'name' => 'fields',
+ 'label' => trans('cubist_back::templates.field_plural'),
+ 'type' => 'textarea'
+ ]);
- /**
- * 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();
+ $this->crud->enableAjaxTable();
}
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)
{
namespace Cubist\Backpack\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 = ['name','description','parent',''];
+ protected $fillable = ['name', 'description', 'parent', 'fields'];
- /**
- * 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)
+ function parent()
{
- $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 = 'template.'.$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;
+ return $this->belongsTo('Cubist\Backpack\app\Models\Template', 'parent');
}
}
+++ /dev/null
-<?php
-
-use Illuminate\Database\Migrations\Migration;
-use Illuminate\Database\Schema\Blueprint;
-
-class CreateTemplateTable extends Migration
-{
- /**
- * Run the migrations.
- *
- * @return void
- */
- public function up()
- {
- Schema::create('cubist_templates', function (Blueprint $table) {
- $table->increments('id');
- $table->string('key')->unique();
- $table->string('name');
- $table->string('description')->nullable();
- $table->string('parent')->nullable();
- $table->json('tabs')->default('[]');
- $table->json('fields')->default('[]');
- $table->tinyInteger('active');
- $table->timestamps();
- });
-
- Schema::create('cubist_subforms', function (Blueprint $table) {
- $table->increments('id');
- $table->string('key')->unique();
- $table->string('name');
- $table->string('description')->nullable();
- $table->string('parent')->nullable();
- $table->json('fields')->default('[]');
- $table->tinyInteger('active');
- $table->timestamps();
- });
- }
-
- /**
- * Reverse the migrations.
- *
- * @return void
- */
- public function down()
- {
- Schema::drop('cubist_templates');
- Schema::drop('cubist_subforms');
- }
-}
--- /dev/null
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+
+class CreateTemplateTable extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::create('cubist_templates', function (Blueprint $table) {
+ $table->increments('id');
+ $table->string('name');
+ $table->string('description')->nullable();
+ $table->string('parent')->nullable();
+ $table->json('fields');
+ $table->timestamps();
+ });
+
+ Schema::create('cubist_subforms', function (Blueprint $table) {
+ $table->increments('id');
+ $table->string('name');
+ $table->string('description')->nullable();
+ $table->string('parent')->nullable();
+ $table->json('fields');
+ $table->timestamps();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::drop('cubist_templates');
+ Schema::drop('cubist_subforms');
+ }
+}
| The following language lines are used for Cubist backpack
|
*/
- 'name' => 'Name',
- 'value' => 'Value',
- 'description' => 'Description',
+ 'name' => 'Name',
+ 'value' => 'Value',
+ 'description' => 'Description',
'template_singular' => 'template',
- 'template_plural' => 'templates',
+ 'template_plural' => 'templates',
+ 'parent' => 'Parent',
+ 'field_singular' => 'Field',
+ 'field_plural' => 'Fields'
];