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
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:
Then {{ $this->data }}
in the view will display "something".