From: Vincent Vanwaelscappel Date: Tue, 25 Jun 2019 15:15:41 +0000 (+0200) Subject: #2843 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=64ea24f01de27aa8da8c0850c92d4507dadaf3ed;p=cubist_cms-back.git #2843 --- diff --git a/src/app/Magic/Controllers/CubistMagicController.php b/src/app/Magic/Controllers/CubistMagicController.php index 742562e..2449b7b 100644 --- a/src/app/Magic/Controllers/CubistMagicController.php +++ b/src/app/Magic/Controllers/CubistMagicController.php @@ -27,4 +27,8 @@ class CubistMagicController extends CubistCrudController { } + + + + } diff --git a/src/app/Magic/Controllers/CubistMagicControllerTrait.php b/src/app/Magic/Controllers/CubistMagicControllerTrait.php index 6e46b1b..b7caf8e 100644 --- a/src/app/Magic/Controllers/CubistMagicControllerTrait.php +++ b/src/app/Magic/Controllers/CubistMagicControllerTrait.php @@ -8,6 +8,7 @@ use Cubist\Backpack\app\Magic\Requests\CubistMagicRequest; use Cubist\Backpack\app\Magic\Requests\CubistMagicStoreRequest; use Cubist\Backpack\app\Magic\Requests\CubistMagicUpdateRequest; use Illuminate\Support\Arr; +use Illuminate\Support\Facades\Redirect; trait CubistMagicControllerTrait { @@ -22,23 +23,23 @@ trait CubistMagicControllerTrait $this->_plural = $this->_singular . 's'; } - if ($this->_clonable) { - $this->crud->allowAccess('clone'); - } - if($this->_oneInstance){ - $this->crud->addClause('where', 'id', 1); + if ($this->_oneInstance) { $this->crud->denyAccess(['create', 'delete']); - }else{ + } else { $this->crud->setCreateView('cubist_back::create'); + if ($this->_clonable) { + $this->crud->allowAccess('clone'); + } + $this->crud->enableExportButtons(); + $this->crud->enablePersistentTable(); } $this->crud->allowAccess('revisions'); - $this->crud->enablePersistentTable(); $this->crud->setEditView('cubist_back::edit'); - $this->crud->enableExportButtons(); + // $this->crud->with('revisionHistory'); @@ -186,8 +187,20 @@ trait CubistMagicControllerTrait return $redirect_location; } + + public function index() + { + if ($this->_oneInstance) { + return Redirect::to('admin/' . $this->_routeURL . '/1/edit'); + } + return parent::index(); + } + public function edit($id) { + if ($this->_oneInstance) { + $id = 1; + } $this->getModelInstance()->onBeforeEdit($this, $id); return parent::edit($id); } diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index 25fbb31..bfaec3c 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -483,7 +483,13 @@ class CubistMagicAbstractModel extends Model implements HasMedia */ public function onBeforeEdit($controller, $id) { - + if ($this->getOption('oneinstance', false)) { + if (null === static::find($id)) { + $class = get_called_class(); + $new = new $class([$this->primaryKey, $id]); + $new->save(); + } + } } /**