From: Vincent Vanwaelscappel Date: Tue, 21 May 2019 14:54:19 +0000 (+0200) Subject: wip #2783 @1.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=92a46520a5964b143248b9331d82c5a92cde394b;p=cubist_cms-back.git wip #2783 @1.5 --- diff --git a/src/app/Http/Controllers/CubistModelCrudController.php b/src/app/Http/Controllers/CubistModelCrudController.php index 11058b9..8b7ccc9 100644 --- a/src/app/Http/Controllers/CubistModelCrudController.php +++ b/src/app/Http/Controllers/CubistModelCrudController.php @@ -2,19 +2,17 @@ namespace Cubist\Backpack\app\Http\Controllers; -use Backpack\CRUD\app\Http\Controllers\CrudController; - -// VALIDATION: change the requests to match your own file names if you need form validation use Cubist\Backpack\app\Http\Requests\CubistModelRequest as StoreRequest; use Cubist\Backpack\app\Http\Requests\CubistModelRequest as UpdateRequest; use Backpack\CRUD\CrudPanel; +use Webfactor\Laravel\Backpack\NestedModels\Controllers\NestedModelsCrudController; /** * Class ModelCrudController * @package App\Http\Controllers\Admin * @property-read CrudPanel $crud */ -class CubistModelCrudController extends CrudController +class CubistModelCrudController extends NestedModelsCrudController { public function setup() { @@ -24,6 +22,7 @@ class CubistModelCrudController extends CrudController |-------------------------------------------------------------------------- */ $this->crud->setModel('Cubist\Backpack\app\Models\CubistModel'); + $this->treeSetup(); $this->crud->setRoute(config('backpack.base.route_prefix') . '/model'); $this->crud->setEntityNameStrings('model', 'models'); @@ -34,7 +33,19 @@ class CubistModelCrudController extends CrudController */ // TODO: remove setFromDb() and manually define Fields and Columns - $this->crud->setFromDb(); + $this->crud->addField(['type' => 'text', 'name' => 'name', 'label' => 'Template table name'], 'create'); + $this->crud->addField(['type' => 'text', 'name' => 'label', 'label' => 'Tamplate label'], 'both'); + $this->crud->addField([ // Table + 'name' => 'attributes', + 'label' => 'Fields definitions', + 'type' => 'table', + 'entity_singular' => 'field', // used on the "Add X" button + 'columns' => [ + 'name' => 'Name', + 'desc' => 'Label', + 'price' => 'Attributes' + ], + ], 'both'); // add asterisk for fields that are required in ModelRequest $this->crud->setRequiredFields(StoreRequest::class, 'create'); diff --git a/src/database/migrations/2019_05_20_161943_create_models_table.php b/src/database/migrations/2019_05_20_161943_create_models_table.php index c1d7a43..a4ddf6a 100644 --- a/src/database/migrations/2019_05_20_161943_create_models_table.php +++ b/src/database/migrations/2019_05_20_161943_create_models_table.php @@ -2,9 +2,12 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; +use Webfactor\Laravel\Backpack\NestedModels\Traits\NestedModelTrait; class CreateModelsTable extends Migration { + use NestedModelTrait; + /** * Run the migrations. * @@ -18,6 +21,7 @@ class CreateModelsTable extends Migration $table->string('label'); $table->json('attributes'); $table->timestamps(); + $table->nestedSet(); }); } @@ -28,6 +32,6 @@ class CreateModelsTable extends Migration */ public function down() { - Schema::drop('models'); + Schema::drop('cubist_models'); } }