Level 2
no one has the same problem ?
Hi,
I've set up a dispatch on my code,but it's not working. What I'm doing wrong ?
In my livewire component I have :
$this->dispatch("document-uploaded.{$this->dossier->id}");
and in my volt component :
new class extends Component {
public DossierModel $dossier;
public int $total = 0;
public int $uploaded = 0;
public bool $all_uploaded = false;
public function mount()
{
$this->total = $this->documents()->count();
$this->uploaded = $this->documents()->filter(fn($doc) => $doc->is_present)->count();
$this->all_uploaded = $this->total == $this->uploaded;
}
public function documents(): Collection
{
return (new \App\Services\DossierDocumentService())->getRequiredDocuments($this->dossier);
}
#[On('document-uploaded.{dossier.id}')]
public function refreshCount(): void
{
$this->total = $this->documents()->count();
$this->uploaded = $this->documents()->filter(fn($doc) => $doc->is_present)->count();
$this->all_uploaded = $this->total == $this->uploaded;
}
}; ?>
...
<flux:navlist.item
icon="document-text"
href="{{ route('hub.dossier.documents', ['dossier' => $this->dossier]) }}"
badge="{{ sprintf('%s/%s', $this->uploaded, $this->total) }}" badge:color="{{ $this->all_uploaded ? 'green' : 'red' }}"
wire:navigate
>
But parameters "uploaded" and "total" are not updated .
Anybody have an idea ?
Please or to participate in this conversation.