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()
{
|--------------------------------------------------------------------------
*/
$this->crud->setModel('Cubist\Backpack\app\Models\CubistModel');
+ $this->treeSetup();
$this->crud->setRoute(config('backpack.base.route_prefix') . '/model');
$this->crud->setEntityNameStrings('model', 'models');
*/
// 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');
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.
*
$table->string('label');
$table->json('attributes');
$table->timestamps();
+ $table->nestedSet();
});
}
*/
public function down()
{
- Schema::drop('models');
+ Schema::drop('cubist_models');
}
}