Only arrays and Traversables can be unpacked

My code is like this:
use Filament\Notifications\Actions\Action;
use Filament\Notifications\Notification;

public function delete(): void
{
Notification::make()
->warning()
->title('Delete confirmation')
->body('Are you sure you want to delete this reply?')
->actions([
Action::make('confirm')
->label('Confirm')
->color('danger')
->button()
->close()
->dispatch('doDelete', [$this->reply->id]),

Action::make('cancel')
->label('Cancel')
->close()
])
->persistent()
->send();
}

public function doDelete(int $reply): void
{
dd($reply);
}
use Filament\Notifications\Actions\Action;
use Filament\Notifications\Notification;

public function delete(): void
{
Notification::make()
->warning()
->title('Delete confirmation')
->body('Are you sure you want to delete this reply?')
->actions([
Action::make('confirm')
->label('Confirm')
->color('danger')
->button()
->close()
->dispatch('doDelete', [$this->reply->id]),

Action::make('cancel')
->label('Cancel')
->close()
])
->persistent()
->send();
}

public function doDelete(int $reply): void
{
dd($reply);
}
After I click on confirm, it gives me the following error: Only arrays and Traversables can be unpacked Where am I wrong? Thank you
9 Replies
awcodes
awcodes11mo ago
Dispatch doesn’t use an array anymore. It uses named arguments. Ie, $this->dispatch('post-created', title: $post->title);
BorNKylleR
BorNKylleR11mo ago
now get this Filament\Actions\StaticAction::dispatch(): Argument #2 ($data) must be of type Closure|array, int given,
->dispatch('doDelete', $this->reply->id),
->dispatch('doDelete', $this->reply->id),
awcodes
awcodes11mo ago
You have to name it. id: $this->reply->id Looks like filament is complaining though, so [‘id’ => $this->reply->id]
BorNKylleR
BorNKylleR11mo ago
So if with this ->dispatch('doDelete', ['id'=>$this->reply->id]), get error Only arrays and Traversables can be unpacked If I trade with this ->dispatch('doDelete', $this->reply->id) get this error Filament\Actions\StaticAction::dispatch(): Argument #2 ($data) must be of type Closure|array, int given I do not understand, Anyway, thanks for the answers, I'll try tomorrow after I get some sleep
awcodes
awcodes11mo ago
Yea. Something is off. It’s telling you to use an array but not accepting an array: Are you importing/using the right Action?
BorNKylleR
BorNKylleR11mo ago
this
use Filament\Notifications\Actions\Action;
use Filament\Notifications\Notification;
use Filament\Notifications\Actions\Action;
use Filament\Notifications\Notification;
stanwarri
stanwarri10mo ago
Hey, I'm currently experiencing this as well. What was the fix?
BorNKylleR
BorNKylleR10mo ago
@stanwarri no i use deleteAction(): Action to get around
stanwarri
stanwarri10mo ago
Oh ok. Passing an array like this worked for me ->dispatch('doDeleteComment', ['commentId' => $commentId]),