diff --git a/packages/support/src/Concerns/HasCellState.php b/packages/support/src/Concerns/HasCellState.php
index e5dda3a7ef..aa73bfc1a2 100644
--- a/packages/support/src/Concerns/HasCellState.php
+++ b/packages/support/src/Concerns/HasCellState.php
@@ -74,20 +74,25 @@ trait HasCellState
return $this->evaluate($this->defaultState);
}
- public function getState(bool $isCached = true): mixed
+ public function getCachedState(): mixed
{
$record = $this->getRecord();
if (! $record) {
- return null;
+ return $this->getState();
}
$recordKey = (string) $record->getKey();
- if ($isCached && array_key_exists($recordKey, $this->cachedState)) {
+ if (array_key_exists($recordKey, $this->cachedState)) {
return $this->cachedState[$recordKey];
}
+ return $this->cachedState[$recordKey] = $this->getState();
+ }
+
+ public function getState(): mixed
+ {
$state = ($this->getStateUsing !== null) ?
$this->evaluate($this->getStateUsing) :
$this->getStateFromRecord();
@@ -103,11 +108,7 @@ trait HasCellState
$state = $this->getDefaultState();
}
- if (! $isCached) {
- return $state;
- }
-
- return $this->cachedState[$recordKey] = $state;
+ return $state;
}
public function getStateFromRecord(): mixed
diff --git a/packages/tables/resources/views/columns/checkbox-column.blade.php b/packages/tables/resources/views/columns/checkbox-column.blade.php
index 6159296684..0fbff95057 100644
--- a/packages/tables/resources/views/columns/checkbox-column.blade.php
+++ b/packages/tables/resources/views/columns/checkbox-column.blade.php
@@ -1,6 +1,6 @@
@php
$isDisabled = $isDisabled();
- $state = (bool) $getState();
+ $state = (bool) $getCachedState();
@endphp
all();
diff --git a/packages/tables/resources/views/columns/icon-column.blade.php b/packages/tables/resources/views/columns/icon-column.blade.php
index c1a68730d8..09980918bc 100644
--- a/packages/tables/resources/views/columns/icon-column.blade.php
+++ b/packages/tables/resources/views/columns/icon-column.blade.php
@@ -1,7 +1,7 @@
@php
use Filament\Tables\Columns\IconColumn\IconColumnSize;
- $arrayState = $getState();
+ $arrayState = $getCachedState();
if ($arrayState instanceof \Illuminate\Support\Collection) {
$arrayState = $arrayState->all();
diff --git a/packages/tables/resources/views/columns/image-column.blade.php b/packages/tables/resources/views/columns/image-column.blade.php
index cf2897a4de..838b7746fc 100644
--- a/packages/tables/resources/views/columns/image-column.blade.php
+++ b/packages/tables/resources/views/columns/image-column.blade.php
@@ -1,5 +1,5 @@
@php
- $state = $getState();
+ $state = $getCachedState();
if ($state instanceof \Illuminate\Support\Collection) {
$state = $state->all();
diff --git a/packages/tables/resources/views/columns/select-column.blade.php b/packages/tables/resources/views/columns/select-column.blade.php
index 95154d8edc..299a485b59 100644
--- a/packages/tables/resources/views/columns/select-column.blade.php
+++ b/packages/tables/resources/views/columns/select-column.blade.php
@@ -2,7 +2,7 @@
$canSelectPlaceholder = $canSelectPlaceholder();
$isDisabled = $isDisabled();
- $state = $getState();
+ $state = $getCachedState();
if ($state instanceof \BackedEnum) {
$state = $state->value;
}
diff --git a/packages/tables/resources/views/columns/text-column.blade.php b/packages/tables/resources/views/columns/text-column.blade.php
index c85621bdbb..88d644f331 100644
--- a/packages/tables/resources/views/columns/text-column.blade.php
+++ b/packages/tables/resources/views/columns/text-column.blade.php
@@ -20,7 +20,7 @@
$alignment = filled($alignment) ? (Alignment::tryFrom($alignment) ?? $alignment) : null;
}
- $arrayState = $getState();
+ $arrayState = $getCachedState();
if ($arrayState instanceof \Illuminate\Support\Collection) {
$arrayState = $arrayState->all();
diff --git a/packages/tables/resources/views/columns/text-input-column.blade.php b/packages/tables/resources/views/columns/text-input-column.blade.php
index e9d3ea303c..6ddab29e8c 100644
--- a/packages/tables/resources/views/columns/text-input-column.blade.php
+++ b/packages/tables/resources/views/columns/text-input-column.blade.php
@@ -2,7 +2,7 @@
use Filament\Support\Enums\Alignment;
$isDisabled = $isDisabled();
- $state = $getState();
+ $state = $getCachedState();
$mask = $getMask();
$alignment = $getAlignment() ?? Alignment::Start;
diff --git a/packages/tables/resources/views/columns/toggle-column.blade.php b/packages/tables/resources/views/columns/toggle-column.blade.php
index 70c220ecd6..dc414ebd8b 100644
--- a/packages/tables/resources/views/columns/toggle-column.blade.php
+++ b/packages/tables/resources/views/columns/toggle-column.blade.php
@@ -1,6 +1,6 @@
@php
$isDisabled = $isDisabled();
- $state = $getState();
+ $state = $getCachedState();
@endphp
[$this->getLivewire()],
'record' => [$this->getRecord()],
'rowLoop' => [$this->getRowLoop()],
- 'state' => [$this->getState()],
+ 'state' => [$this->getCachedState()],
'table' => [$this->getTable()],
default => parent::resolveDefaultClosureDependencyForEvaluationByName($parameterName),
};
diff --git a/packages/tables/src/Columns/Concerns/CanBeCopied.php b/packages/tables/src/Columns/Concerns/CanBeCopied.php
index d92cf66d8c..7fafe68e8e 100644
--- a/packages/tables/src/Columns/Concerns/CanBeCopied.php
+++ b/packages/tables/src/Columns/Concerns/CanBeCopied.php
@@ -15,7 +15,7 @@ trait CanBeCopied
return true;
}
- $state = $this->getState();
+ $state = $this->getCachedState();
if (! is_array($state)) {
return $this->isCopyable($state);
diff --git a/packages/tables/src/Testing/TestsColumns.php b/packages/tables/src/Testing/TestsColumns.php
index d825f03e60..d2c902a90b 100644
--- a/packages/tables/src/Testing/TestsColumns.php
+++ b/packages/tables/src/Testing/TestsColumns.php
@@ -180,7 +180,7 @@ class TestsColumns
$livewireClass = $this->instance()::class;
- $state = $column->getState(isCached: false);
+ $state = $column->getState();
if (is_array($state)) {
$state = json_encode($state);
@@ -216,7 +216,7 @@ class TestsColumns
$livewireClass = $this->instance()::class;
- $state = $column->getState(isCached: false);
+ $state = $column->getState();
if (is_array($state)) {
$state = json_encode($state);
@@ -254,7 +254,7 @@ class TestsColumns
Assert::assertEquals(
$value,
- $column->formatState($column->getState(isCached: false)),
+ $column->formatState($column->getState()),
message: "Failed asserting that a table column with name [{$name}] has a formatted state of [{$value}] for record [{$record->getKey()}] on the [{$livewireClass}] component.",
);
@@ -280,7 +280,7 @@ class TestsColumns
$livewireClass = $this->instance()::class;
Assert::assertFalse(
- $column->formatState($column->getState(isCached: false)) == $value,
+ $column->formatState($column->getState()) == $value,
message: "Failed asserting that a table column with name [{$name}] does not have a formatted state of [{$value}] for record [{$record->getKey()}] on the [{$livewireClass}] component.",
);