Skip to content

Commit 5e3a124

Browse files
committed
add key method to properly allow changing column key
1 parent f579d9a commit 5e3a124

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/app/Library/CrudPanel/CrudColumn.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* @method self visibleInExport(bool $value)
2626
* @method self visibleInShow(bool $value)
2727
* @method self priority(int $value)
28+
* @method self key(string $value)
2829
*/
2930
class CrudColumn
3031
{
@@ -66,6 +67,24 @@ public static function name($name)
6667
return new static($name);
6768
}
6869

70+
/**
71+
* Change the CrudColumn key
72+
*
73+
* @param string $key New key for the column
74+
* @return CrudColumn
75+
*/
76+
public function key(string $key)
77+
{
78+
if(!isset($this->attributes['name'])) {
79+
abort(500, 'Column name must be defined before changing the key.');
80+
}
81+
if ($this->crud()->hasColumnWhere('key', $this->attributes['key'])) {
82+
$this->crud()->setColumnDetails($this->attributes['key'], array_merge($this->attributes, ['key' => $key]));
83+
}
84+
$this->attributes['key'] = $key;
85+
return $this;
86+
}
87+
6988
/**
7089
* Remove the current column from the current operation.
7190
*

0 commit comments

Comments
 (0)