]> _ Git - cubist_cms-back.git/commitdiff
#2783
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 21 May 2019 16:05:12 +0000 (18:05 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 21 May 2019 16:05:12 +0000 (18:05 +0200)
src/app/Http/Controllers/CubistCrudController.php [new file with mode: 0644]
src/app/Http/Controllers/CubistModelCrudController.php

diff --git a/src/app/Http/Controllers/CubistCrudController.php b/src/app/Http/Controllers/CubistCrudController.php
new file mode 100644 (file)
index 0000000..b974569
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+
+
+namespace Cubist\Backpack\app\Http\Controllers;
+
+trait CubistCrudController
+{
+    public function addField($field, $form = 'both')
+    {
+        if (isset($field['column_label']) || isset($field['column']) && $field['column'] == true) {
+            $column_data = ['name' => $field['name'], 'label' => $field['label'], 'type' => 'text'];
+            if (isset($field['column'])) {
+                unset($field['column']);
+            }
+            if (isset($field['column_label'])) {
+                $column_data['label'] = $field['column_label'];
+                unset($field['column_label']);
+            }
+            if (isset($field['column_type'])) {
+                $column_data['type'] = $field['column_type'];
+                unset($column_data['type']);
+            }
+            $this->crud->addColumn($column_data);
+        }
+        $this->crud->addField($field, $form);
+    }
+}
index ac06050cdea924c3f6069608423b656a32d0bc66..c944fbe9f2c53d06055b20caad1fabb7cf657e65 100644 (file)
@@ -16,6 +16,8 @@ use Backpack\CRUD\CrudPanel;
  */
 class CubistModelCrudController extends CrudController
 {
+    use CubistCrudController;
+
     public function setup()
     {
         /*
@@ -33,9 +35,12 @@ class CubistModelCrudController extends CrudController
         |--------------------------------------------------------------------------
         */
 
-        $this->crud->addField(['type' => 'text', 'name' => 'name', 'label' => 'Template table name'], 'create');
-        $this->crud->addField(['type' => 'text', 'name' => 'label', 'label' => 'Tamplate label'], 'both');
-        $this->crud->addField(['type' => 'textarea', 'name' => 'attributes', 'label' => 'Fields definitions'], 'both');
+        $this->addField(['type' => 'text',
+            'name' => 'name',
+            'label' => 'Model table name',
+            'column' => true], 'create');
+        $this->addField(['type' => 'text', 'name' => 'label', 'label' => 'Model label', 'column' => true], 'both');
+        $this->addField(['type' => 'textarea', 'name' => 'attributes', 'label' => 'Fields definitions'], 'both');
 
         // add asterisk for fields that are required in ModelRequest
         $this->crud->setRequiredFields(StoreRequest::class, 'create');