F
Filament6mo 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
Sylfel6mo ago
Did you try to remove your « mount » function ?
dyo
dyoOP6mo ago
yes I did, but $this->record is null
Vp
Vp6mo ago
Did you use this inside "EDIT" or "VIEW" as mentioned in docs linked
dyo
dyoOP6mo ago
thanks, that what I need..
Want results from more Discord servers?
Add your server