Skip to content

Commit f8ddfd9

Browse files
Merge pull request #73 from CodeWithDennis/revert-changes
Revert changes
2 parents 1f525c4 + 25069b5 commit f8ddfd9

File tree

2 files changed

+7
-28
lines changed

2 files changed

+7
-28
lines changed

README.md

-7
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,6 @@ Hide specific options in the tree
132132
->hiddenOptions([2, 3, 4])
133133
```
134134

135-
Specify a different key for your model.
136-
For example: you have id, code and parent_code. Your model uses id as key, but the parent-child relation is established between code and parent_code
137-
138-
```PHP
139-
->withKey('code')
140-
```
141-
142135
## Filters
143136
Use the tree in your table filters. Here's an example to show you how.
144137

src/SelectTree.php

+7-21
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ class SelectTree extends Field implements HasAffixActions
3737

3838
protected bool $independent = true;
3939

40-
protected string $customKey = null;
41-
4240
protected string $titleAttribute;
4341

4442
protected string $parentAttribute;
@@ -113,7 +111,7 @@ protected function setUp(): void
113111

114112
$form->model($record)->saveRelationships();
115113

116-
return $record->{$this->getCustomKey()};
114+
return $record->getKey();
117115
});
118116

119117
$this->suffixActions([
@@ -186,18 +184,18 @@ private function buildNode($result, $resultMap, $disabledOptions, $hiddenOptions
186184
// Create a node with 'name' and 'value' attributes
187185
$node = [
188186
'name' => $result->{$this->getTitleAttribute()},
189-
'value' => $result->{$this->getCustomKey()},
190-
'disabled' => in_array($result->{$this->getCustomKey()}, $disabledOptions),
191-
'hidden' => in_array($result->{$this->getCustomKey()}, $hiddenOptions),
187+
'value' => $result->getKey(),
188+
'disabled' => in_array($result->getKey(), $disabledOptions),
189+
'hidden' => in_array($result->getKey(), $hiddenOptions),
192190
];
193191

194192
// Check if the result has children
195-
if (isset($resultMap[$result->{$this->getCustomKey()}])) {
193+
if (isset($resultMap[$result->getKey()])) {
196194
$children = collect();
197195
// Recursively build child nodes
198-
foreach ($resultMap[$result->{$this->getCustomKey()}] as $child) {
196+
foreach ($resultMap[$result->getKey()] as $child) {
199197
// don't add the hidden ones
200-
if (in_array($child->{$this->getCustomKey()}, $hiddenOptions)) {
198+
if (in_array($child->getKey(), $hiddenOptions)) {
201199
continue;
202200
}
203201
$childNode = $this->buildNode($child, $resultMap, $disabledOptions, $hiddenOptions);
@@ -303,13 +301,6 @@ public function independent(bool $independent = true): static
303301
return $this;
304302
}
305303

306-
public function withKey(string $customKey = 'id'): static
307-
{
308-
$this->customKey = $customKey;
309-
310-
return $this;
311-
}
312-
313304
public function disabledOptions(Closure|array $disabledOptions): static
314305
{
315306
$this->disabledOptions = $disabledOptions;
@@ -358,11 +349,6 @@ public function getIndependent(): bool
358349
return $this->evaluate($this->independent);
359350
}
360351

361-
public function getCustomKey(): string
362-
{
363-
return $this->customKey ? $this->evaluate($this->customKey) : $this->getKey();
364-
}
365-
366352
public function getWithCount(): bool
367353
{
368354
return $this->evaluate($this->withCount);

0 commit comments

Comments
 (0)