FilamentF
Filament2y ago
dyo

Problem in accessing widget current record

https://filamentphp.com/docs/3.x/panels/resources/widgets#accessing-the-current-record-in-the-widget

Can someone help me explain more about accessing widget current record?

My widget class:
public ?Model $record = null;

protected static ?string $pollingInterval = '30s';

public function mount($record)
{
    $this->record = $record;
}

protected function getCards(): array
{
    dd($this->record);
    $total = max(Konfirmasi::where('campaigns_id', $this->record)->count(), 1);

    $pending = Campaign::find($this->record)
        ->konfirmasi()->pending()->count();

    return [
        Stat::make('Completed', $sukses)
            ->color('success')
            ->description('Rp ' . number_format(Campaign::find($this->record)
                ->konfirmasi()->sukses()->sum('dana'))
                . ' (' . number_format($sukses / $total * 100, 1) . '%)')
            ->descriptionIcon('heroicon-m-check-badge'),

I get error
Unable to resolve dependency [Parameter #0 [ <required> $record ]] in class Widget

What should I do?
Was this page helpful?