The method of listening for events has also been updated in Livewire v3, it may be worth an extra example to demonstrate, e.g. this is a complete example of adding a Widget to the ListOrder Page:
<?php
declare(strict_types=1);
namespace App\Filament\Resources\OrderResource\Pages;
use App\Filament\Resources\OrderResource;
use Filament\Actions;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
use Livewire\Attributes\On;
class ListOrders extends ListRecords
{
protected static string $resource = OrderResource::class;
#[On('setStatusFilter')]
public function setStatusFilter(string $filter): void
{
$this->tableFilters[$filter]['isActive'] = true;
}
protected function getHeaderActions(): array
{
return [
CreateAction::make(),
];
}
protected function getHeaderWidgets(): array
{
return [
OrderResource\Widgets\OrdersOverview::class,
];
}
}
I welcome your feedback and can make the time to update the documentation.
Package
filament/widgets
Package Version
v3.0.51
Laravel Version
v10.23.1
Livewire Version
v3.0.3
PHP Version
PHP v8.2.3
Problem description
I'm following the documentation for dispatching events from Widgets and getting the following error:
Only arrays and Traversables can be unpacked
Expected behavior
When dispatching events from Widgets the listener on the resource should be called with the data provided
Steps to reproduce
Create a Widget and add extra attributes. This is the current documentation:
The Livewire documentation has been updated, the "processed" value can not be a string, Livewire is expecting an array:
https://livewire.laravel.com/docs/events#dispatching-events-from-blade-templates
Note the value is now a javascript object syntax wrapped in curly brackets {}.
The fix is to update the documentation. After a little experimenting this worked:
My preference is to escape the $ in the text, as the output in the browser is much cleaner and easier to read:
If the attribute is prepared from the current documentation
'$dispatch("setStatusFilter", {filter: "processed"})'
the output is escaped:The output is escaped:
This doesn't work!
I propose the domination be updated to the Livewire syntax, open the string with ", use ' inside the string, and escape the $.
The method of listening for events has also been updated in Livewire v3, it may be worth an extra example to demonstrate, e.g. this is a complete example of adding a Widget to the ListOrder Page:
I welcome your feedback and can make the time to update the documentation.
Reproduction repository
https://github.com/filamentphp/filament/blob/3.x/packages/widgets/
Relevant log output