F
Filament11mo ago
ded7978

How i can get my own data or id of item in widgets.

I put widgets in edit page. Now i have to take data from database or somwhere. $this->data doesnt work class StatsOverview extends BaseWidget { protected function getStats(): array { return [ Stat::make('Sent', 'mydata'), Stat::make('Delivered', '21%'), Stat::make('Viewed', '3:12'), ]; } }
2 Replies
X7Ryan
X7Ryan11mo ago
A widget is essentially at it's core a Livewire component, which means you get access to Livewire features. So you can add a computed property. So if you want to access $this->data in the view just add this to the widget class:
#[Computed]
public function data(): string
{
return 'something';
}
#[Computed]
public function data(): string
{
return 'something';
}
Then {{ $this->data }} in the view will display "something".