]> _ Git - cubist_cms-back.git/commitdiff
#2843
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 25 Jun 2019 15:15:41 +0000 (17:15 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 25 Jun 2019 15:15:41 +0000 (17:15 +0200)
src/app/Magic/Controllers/CubistMagicController.php
src/app/Magic/Controllers/CubistMagicControllerTrait.php
src/app/Magic/Models/CubistMagicAbstractModel.php

index 742562ee10f8668829ba5411db072c0045a808a6..2449b7b47651d4659bf0eac8b2553c733b7a1241 100644 (file)
@@ -27,4 +27,8 @@ class CubistMagicController extends CubistCrudController
     {
 
     }
+
+
+
+
 }
index 6e46b1b2ce0a5529e082df3ccea205bae3128348..b7caf8e861f1c32a7edf1c7bf4f0db6142ee2e88 100644 (file)
@@ -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);
     }
index 25fbb313cbef624f2b8beec365b3941d2a4e14da..bfaec3cb6d7c665ae1dd4e839930a615421f644a 100644 (file)
@@ -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();
+            }
+        }
     }
 
     /**