F
Filament4w 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'),
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?
5 Replies
Sylfel
Sylfel4w ago
Did you try to remove your « mount » function ?
dyo
dyo4w ago
yes I did, but $this->record is null
Vp
Vp4w ago
Did you use this inside "EDIT" or "VIEW" as mentioned in docs linked
dyo
dyo4w ago
thanks, that what I need..