Skip to content

Commit 1ba2ad0

Browse files
committed
ShowOperation should not add fields by default; add parameters to setFromDb()
1 parent 0215a39 commit 1ba2ad0

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

src/app/Http/Controllers/Operations/ShowOperation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function show($id)
7979

8080
// set columns from db
8181
if ($setFromDb) {
82-
$this->crud->setFromDb();
82+
$this->crud->setFromDb(false, true);
8383
}
8484

8585
// cycle through columns

src/app/Library/CrudPanel/Traits/AutoSet.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,27 @@ trait AutoSet
1010
*
1111
* @return void
1212
*/
13-
public function setFromDb()
13+
public function setFromDb($setFields = true, $setColumns = true)
1414
{
1515
if ($this->driverIsSql()) {
1616
$this->getDbColumnTypes();
1717
}
1818

19-
array_map(function ($field) {
20-
$new_field = [
21-
'name' => $field,
22-
'label' => $this->makeLabel($field),
23-
'value' => null,
24-
'default' => isset($this->autoset['db_column_types'][$field]['default']) ? $this->autoset['db_column_types'][$field]['default'] : null,
25-
'type' => $this->inferFieldTypeFromDbColumnType($field),
26-
'values' => [],
27-
'attributes' => [],
28-
'autoset' => true,
29-
];
30-
31-
if (! isset($this->fields()[$field])) {
32-
$this->addField($new_field);
19+
array_map(function ($field) use ($setFields, $setColumns) {
20+
if ($setFields && ! isset($this->fields()[$field])) {
21+
$this->addField([
22+
'name' => $field,
23+
'label' => $this->makeLabel($field),
24+
'value' => null,
25+
'default' => isset($this->autoset['db_column_types'][$field]['default']) ? $this->autoset['db_column_types'][$field]['default'] : null,
26+
'type' => $this->inferFieldTypeFromDbColumnType($field),
27+
'values' => [],
28+
'attributes' => [],
29+
'autoset' => true,
30+
]);
3331
}
3432

35-
if (! in_array($field, $this->model->getHidden()) && ! in_array($field, $this->columns())) {
33+
if ($setColumns && ! in_array($field, $this->model->getHidden()) && ! isset($this->columns()[$field])) {
3634
$this->addColumn([
3735
'name' => $field,
3836
'label' => $this->makeLabel($field),

0 commit comments

Comments
 (0)