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
awcodes16mo ago
Dispatch doesn’t use an array anymore. It uses named arguments. Ie, $this->dispatch('post-created', title: $post->title);
BorNKylleR
BorNKylleROP16mo 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
awcodes16mo ago
You have to name it. id: $this->reply->id Looks like filament is complaining though, so [‘id’ => $this->reply->id]
BorNKylleR
BorNKylleROP16mo 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
awcodes16mo 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
BorNKylleROP16mo ago
this
use Filament\Notifications\Actions\Action;
use Filament\Notifications\Notification;
use Filament\Notifications\Actions\Action;
use Filament\Notifications\Notification;
stanwarri
stanwarri15mo ago
Hey, I'm currently experiencing this as well. What was the fix?
BorNKylleR
BorNKylleROP15mo ago
@stanwarri no i use deleteAction(): Action to get around
stanwarri
stanwarri15mo ago
Oh ok. Passing an array like this worked for me ->dispatch('doDeleteComment', ['commentId' => $commentId]),
Want results from more Discord servers?
Add your server