use Backpack\CRUD\ModelTraits\SpatieTranslatable\SluggableScopeHelpers;
use Backpack\CRUD\ModelTraits\SpatieTranslatable\HasTranslations;
use Doctrine\DBAL\Schema\Schema;
+use Doctrine\DBAL\Schema\Table;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
protected static $_doctrineTypesMapping = ['int' => 'integer'];
- protected $nested = false;
protected $primaryKey = 'id';
public $timestamps = true;
public function __construct(array $attributes = [])
{
$this->setFields();
+ $this->afterSetFields();
$this->bootIfNotBooted();
$this->initializeTraits();
$this->syncOriginal();
}
+
+ public function afterSetFields()
+ {
+ if (!isset($this->_fields['slug'])) {
+ $this->addField(['name' => 'slug',
+ 'type' => 'Slug',
+ 'label' => 'Slug',
+ 'translatable' => true,
+ 'hidden' => true,
+ 'fillable' => false]);
+ }
+ }
+
+
public function getFields()
{
return $this->_fields;
return $this->getStudlyName() . 'CrudController';
}
+ /**
+ * @return string
+ */
+ protected function _getBaseController()
+ {
+ return 'CubistMagicController';
+ }
+
protected function _replaceInCode($stub, $dest)
{
$vars = ['CONTROLLERCLASS' => $this->getControllerClass(),
'SINGULAR' => $this->getOption('singular', $this->getOption('name')),
'PLURAL' => $this->getOption('plural', ''),
'MODELNAMESPACE' => get_class($this),
- 'EXTENDS' => $this->nested ? 'CubistNestedMagicController' : 'CubistMagicController',
+ 'EXTENDS' => $this->_getBaseController(),
];
$res = file_get_contents($stub);
/**
* @param $schema Schema
+ * @return Table
*/
public function setSchema($schema)
{
$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);
$table->addColumn(static::UPDATED_AT, 'date', $options);
$table->addColumn('deleted_at', 'date', $options);
}
+ return $table;
}
public function replicate(array $except = null)
namespace Cubist\Backpack\app\Magic\Models;
-
use Webfactor\Laravel\Backpack\NestedModels\Traits\NestedModelTrait;
class CubistMagicNestedModel extends CubistMagicModel
$this->replicateNodeTrait($except);
$this->replicateSluggable($except);
}
+
+ public function setSchema($schema)
+ {
+ $table = parent::setSchema($schema);
+
+ $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]);
+
+ return $table;
+ }
+
+ /**
+ * @return string
+ */
+ protected function _getBaseController(){
+ return 'CubistMagicController';
+ }
+
}