diff --git a/packages/panels/resources/views/components/page/index.blade.php b/packages/panels/resources/views/components/page/index.blade.php
index f90c4eb835..1ea714212a 100644
--- a/packages/panels/resources/views/components/page/index.blade.php
+++ b/packages/panels/resources/views/components/page/index.blade.php
@@ -114,11 +114,9 @@
@if (! ($this instanceof \Filament\Tables\Contracts\HasTable))
- @elseif ($this->isTableLoaded() &&
- filled($this->defaultTableAction) &&
- filled($this->defaultTableActionRecord))
+ @elseif ($this->isTableLoaded() && filled($this->defaultTableAction))
@endif
diff --git a/packages/tables/src/Concerns/HasActions.php b/packages/tables/src/Concerns/HasActions.php
index 3aa1c479a2..eccd62afd7 100644
--- a/packages/tables/src/Concerns/HasActions.php
+++ b/packages/tables/src/Concerns/HasActions.php
@@ -29,6 +29,11 @@ trait HasActions
*/
public ?array $mountedTableActionsData = [];
+ /**
+ * @var array> | null
+ */
+ public ?array $mountedTableActionsArguments = [];
+
/**
* @var int | string | null
*/
@@ -44,6 +49,12 @@ trait HasActions
#[Url(as: 'tableAction')]
public $defaultTableAction = null;
+ /**
+ * @var mixed
+ */
+ #[Url(as: 'tableActionArguments')]
+ public $defaultTableActionArguments = null;
+
/**
* @var mixed
*/
@@ -79,6 +90,8 @@ trait HasActions
$result = null;
+ $originallyMountedActions = $this->mountedTableActions;
+
try {
if ($this->mountedTableActionHasForm()) {
$action->callBeforeFormValidated();
@@ -116,6 +129,12 @@ trait HasActions
$action->resetArguments();
$action->resetFormData();
+ // If the action was replaced while it was being called,
+ // we don't want to unmount it.
+ if ($originallyMountedActions !== $this->mountedTableActions) {
+ return null;
+ }
+
$this->unmountTableAction();
return $result;
@@ -126,9 +145,13 @@ trait HasActions
$this->mountedTableActionRecord = $record;
}
- public function mountTableAction(string $name, ?string $record = null): mixed
+ /**
+ * @param array $arguments
+ */
+ public function mountTableAction(string $name, ?string $record = null, array $arguments = []): mixed
{
$this->mountedTableActions[] = $name;
+ $this->mountedTableActionsArguments[] = $arguments;
$this->mountedTableActionsData[] = [];
if (count($this->mountedTableActions) === 1) {
@@ -190,6 +213,15 @@ trait HasActions
return null;
}
+ /**
+ * @param array $arguments
+ */
+ public function replaceMountedTableAction(string $name, ?string $record = null, array $arguments = []): void
+ {
+ $this->resetMountedTableActionProperties();
+ $this->mountTableAction($name, $record ?? $this->mountedTableActionRecord, $arguments);
+ }
+
public function mountedTableActionShouldOpenModal(): bool
{
$action = $this->getMountedTableAction();
@@ -270,6 +302,7 @@ trait HasActions
protected function resetMountedTableActionProperties(): void
{
$this->mountedTableActions = [];
+ $this->mountedTableActionsArguments = [];
$this->mountedTableActionsData = [];
}
@@ -305,6 +338,7 @@ trait HasActions
// Setting these to `null` creates a bug where the properties are
// actually set to `'null'` strings and remain in the URL.
$this->defaultTableAction = [];
+ $this->defaultTableActionArguments = [];
$this->defaultTableActionRecord = [];
return;
diff --git a/packages/tables/src/Contracts/HasTable.php b/packages/tables/src/Contracts/HasTable.php
index 42b2c633a1..2cf30052dd 100644
--- a/packages/tables/src/Contracts/HasTable.php
+++ b/packages/tables/src/Contracts/HasTable.php
@@ -107,4 +107,9 @@ interface HasTable
public function getFilteredSortedTableQuery(): Builder;
public function makeFilamentTranslatableContentDriver(): ?TranslatableContentDriver;
+
+ /**
+ * @param array $arguments
+ */
+ public function replaceMountedTableAction(string $name, ?string $record = null, array $arguments = []): void;
}
diff --git a/packages/tables/src/Table/Concerns/HasActions.php b/packages/tables/src/Table/Concerns/HasActions.php
index 449ffaefda..c4c1de3767 100644
--- a/packages/tables/src/Table/Concerns/HasActions.php
+++ b/packages/tables/src/Table/Concerns/HasActions.php
@@ -181,6 +181,15 @@ trait HasActions
*/
protected function getMountableModalActionFromAction(Action $action, array $modalActionNames, ?Model $mountedRecord = null): ?Action
{
+ $arguments = $this->getLivewire()->mountedTableActionsArguments ?? [];
+
+ if (
+ (($actionArguments = array_shift($arguments)) !== null) &&
+ (! $action->hasArguments())
+ ) {
+ $action->arguments($actionArguments);
+ }
+
foreach ($modalActionNames as $modalActionName) {
$action = $action->getMountableModalAction($modalActionName);
@@ -191,6 +200,13 @@ trait HasActions
if ($action instanceof Action) {
$action->record($mountedRecord);
}
+
+ if (
+ (($actionArguments = array_shift($arguments)) !== null) &&
+ (! $action->hasArguments())
+ ) {
+ $action->arguments($actionArguments);
+ }
}
if (! $action instanceof Action) {