Possible to pass parameters to a widget?

Am I going about this all wrong? I just need to filter the query being used for the widget. Here's my code:
class StatementOverview extends BaseWidget
{
protected static ?string $pollingInterval = null;
protected Document $document;

//this doesn't work, but this is kind of what I need to do..
public function mount($documentId)
{
$this->document = Document::find($documentId);
}

protected function getStats(): array
{
return [
Stat::make('Total of Matches', '$' . number_format($this->getTotalOfMatches() / 100, 2, '.', ',')),
];
}

protected function getTotalOfMatches()
{
return StatementTransaction::where('document_id', $this->document->id)
->where('some_other_filters_here', true)
->sum('amount');
}
}
class StatementOverview extends BaseWidget
{
protected static ?string $pollingInterval = null;
protected Document $document;

//this doesn't work, but this is kind of what I need to do..
public function mount($documentId)
{
$this->document = Document::find($documentId);
}

protected function getStats(): array
{
return [
Stat::make('Total of Matches', '$' . number_format($this->getTotalOfMatches() / 100, 2, '.', ',')),
];
}

protected function getTotalOfMatches()
{
return StatementTransaction::where('document_id', $this->document->id)
->where('some_other_filters_here', true)
->sum('amount');
}
}
`
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server