Skip to content

Commit 5f976d9

Browse files
Introduce new method withTrashed()
1 parent db8ca2e commit 5f976d9

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/SelectTree.php

+16-2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class SelectTree extends Field implements HasAffixActions
7575

7676
protected ?Closure $createOptionUsing = null;
7777

78+
protected Closure|bool|null $withTrashed = false;
79+
7880
protected function setUp(): void
7981
{
8082
// Load the state from relationships using a callback function.
@@ -133,8 +135,8 @@ private function buildTree(): Collection
133135
}
134136

135137
// Fetch results for both queries
136-
$nullParentResults = $nullParentQuery->get();
137-
$nonNullParentResults = $nonNullParentQuery->get();
138+
$nullParentResults = $nullParentQuery->withTrashed($this->withTrashed)->get();
139+
$nonNullParentResults = $nonNullParentQuery->withTrashed($this->withTrashed)->get();
138140

139141
// Combine the results from both queries
140142
$combinedResults = $nullParentResults->concat($nonNullParentResults);
@@ -230,6 +232,13 @@ public function withCount(bool $withCount = true): static
230232
return $this;
231233
}
232234

235+
public function withTrashed(bool $withTrashed = true): static
236+
{
237+
$this->withTrashed = $withTrashed;
238+
239+
return $this;
240+
}
241+
233242
public function direction(string $direction): static
234243
{
235244
$this->direction = $direction;
@@ -356,6 +365,11 @@ public function getGrouped(): bool
356365
return $this->evaluate($this->grouped);
357366
}
358367

368+
public function getWithTrashed(): bool
369+
{
370+
return $this->evaluate($this->withTrashed);
371+
}
372+
359373
public function getIndependent(): bool
360374
{
361375
return $this->evaluate($this->independent);

0 commit comments

Comments
 (0)