Skip to content

Commit 883d97c

Browse files
authored
Merge pull request #4504 from Laravel-Backpack/fluent-columns-key
Fluent columns, add key() function to properly allow overrides
2 parents f579d9a + 14bd6c0 commit 883d97c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/app/Library/CrudPanel/CrudColumn.php

Lines changed: 20 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,25 @@ 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+
86+
return $this;
87+
}
88+
6989
/**
7090
* Remove the current column from the current operation.
7191
*

0 commit comments

Comments
 (0)