Skip to content

Commit 36d70e2

Browse files
authored
Merge pull request #4548 from Laravel-Backpack/fix-column-key-definition
Fix column key definition
2 parents 2d91f78 + 0d9f45c commit 36d70e2

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/app/Library/CrudPanel/CrudColumn.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,18 @@ public function key(string $key)
7878
if (! isset($this->attributes['name'])) {
7979
abort(500, 'Column name must be defined before changing the key.');
8080
}
81-
if ($this->crud()->hasColumnWhere('key', $this->attributes['key'])) {
82-
$this->crud()->setColumnDetails($this->attributes['key'], array_merge($this->attributes, ['key' => $key]));
81+
82+
$columns = $this->crud()->columns();
83+
$searchKey = $this->attributes['key'];
84+
$column = $this->attributes;
85+
86+
if (isset($columns[$searchKey])) {
87+
unset($columns[$searchKey]);
88+
$column['key'] = $key;
8389
}
84-
$this->attributes['key'] = $key;
90+
91+
$this->attributes = $column;
92+
$this->setOperationSetting('columns', array_merge($columns, [$key => $column]));
8593

8694
return $this;
8795
}

0 commit comments

Comments
 (0)