'tab' => 'Informations principales',
]);
+ $this->addField(['name' => 'slug',
+ 'label' => 'Slug (URL)',
+ 'type' => 'Slug',
+ 'tab' => 'Informations principales',
+ ]);
+
$this->_common();
}
use Cubist\Backpack\app\Magic\Fields\Field;
use Cubist\Backpack\app\Magic\Requests\CubistMagicUpdateRequest;
use Cubist\Backpack\app\Magic\Util;
-use Backpack\CRUD\ModelTraits\SpatieTranslatable\HasTranslations;
use Backpack\CRUD\ModelTraits\SpatieTranslatable\Sluggable;
use Backpack\CRUD\ModelTraits\SpatieTranslatable\SluggableScopeHelpers;
+use Backpack\CRUD\ModelTraits\SpatieTranslatable\HasTranslations;
use Cubist\Util\Json;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
class CubistMagicAbstractModel extends Model implements HasMedia
{
use CrudTrait;
- use Sluggable {
- replicate as protected replicateSluggable;
- }
+ use Sluggable;
use SluggableScopeHelpers;
use HasTranslations {
update as protected updateTranslations;
$table->addColumn('deleted_at', 'datetime', $options);
}
- public function replicate(array $except = null)
- {
- return $this->replicateSluggable($except);
- }
-
public function __call($method, $parameters)
{
return $this->createTranslations($attributes);
}
+ public function getSlugAttribute($value){
+ if(!$value){
+ return Str::slug($this->title);
+ }
+ return $value;
+ }
+
/**
* @param $controller CubistMagicController
*/
{
return 'CubistMagicNestedController';
}
+
+
+ public static function getTree()
+ {
+ $all = self::orderBy('lft')->get();
+ $res = [];
+ self::_appendToTree($res, null, $all);
+
+ return $res;
+ }
+
+ /**
+ * @param array $tree
+ * @param $id
+ * @param self[] $all
+ */
+ public static function _appendToTree(&$tree, $id, $all)
+ {
+ foreach ($all as $e) {
+ if ($e->parent_id != $id) {
+ continue;
+ }
+ $item = ['element' => $e, 'children' => []];
+ self::_appendToTree($item['children'], $e->id, $all);
+ $tree[$e->name] = $item;
+ }
+ }
}