namespace Cubist\Backpack\app\Magic\Controllers;
-use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\CrudTrait;
use Cubist\Backpack\app\Magic\Fields\Field;
use Cubist\Backpack\app\Magic\Models\CubistMagicModelAbstract;
use Cubist\Backpack\app\Magic\Requests\CubistMagicStoreRequest;
use Cubist\Backpack\app\Magic\Requests\CubistMagicUpdateRequest;
+use Webfactor\Laravel\Backpack\NestedModels\Controllers\NestedModelsCrudController;
+use Webfactor\Laravel\Backpack\NestedModels\Traits\NestedModelTrait;
-class CubistMagicController extends CrudController
+class CubistMagicController extends NestedModelsCrudController
{
- use CrudTrait;
+ use CrudTrait, NestedModelTrait;
protected $_modelNamespace;
protected $_routeURL;
protected $_singular;
protected $_plural;
+ protected $_nested = false;
protected $_storeRequest;
protected $_updateRequest;
|--------------------------------------------------------------------------
*/
$this->crud->setModel($this->_modelNamespace);
+ if ($this->_nested) {
+ $this->treeSetup();
+ }
$this->crud->setRoute(config('backpack.base.route_prefix') . '/' . $this->_routeURL);
$this->crud->setEntityNameStrings($this->_singular, $this->_plural);
use Illuminate\Database\Eloquent\Model;
use Cubist\Backpack\app\Magic\CubistMagicAttribute;
use Illuminate\Support\Str;
+use Webfactor\Laravel\Backpack\NestedModels\Traits\NestedModelTrait;
class CubistMagicModelAbstract extends Model
{
use CubistMagicAttribute;
- use CrudTrait;
+ use CrudTrait, NestedModelTrait;
use Sluggable, SluggableScopeHelpers;
protected static $_doctrineTypesMapping = ['int' => 'integer'];
+ protected $nested = false;
protected $primaryKey = 'id';
public $timestamps = true;
'ROUTEURL' => $this->getOption('name'),
'SINGULAR' => $this->getOption('singular', $this->getOption('name')),
'PLURAL' => $this->getOption('plural', ''),
- 'MODELNAMESPACE' => get_class($this)
+ 'MODELNAMESPACE' => get_class($this),
+ 'NESTED' => $this->nested ? 'true' : 'false',
];
$res = file_get_contents($stub);
$field->defineDbColumn($table);
}
+ if ($this->nested) {
+ $table->addColumn('parent_id', 'integer', ['unsigned' => true, 'notnull' => false]);
+ $table->addIndex(['parent_id']);
+ $table->addColumn('lft', 'integer', ['unsigned' => true, 'default' => 0]);
+ $table->addIndex(['lft']);
+ $table->addColumn('rgt', 'integer', ['unsigned' => true, 'default' => 0]);
+ $table->addIndex(['rgt']);
+ $table->addColumn('depth', 'integer', ['unsigned' => true, 'default' => 0]);
+ }
+
if ($this->timestamps) {
$options = ['notnull' => false];
$table->addColumn(static::CREATED_AT, 'date', $options);