Skip to content

Instantly share code, notes, and snippets.

@nuernbergerA
Created February 19, 2024 15:53
Show Gist options
  • Save nuernbergerA/5a328de091d700317cf983573c0ab22f to your computer and use it in GitHub Desktop.
Save nuernbergerA/5a328de091d700317cf983573c0ab22f to your computer and use it in GitHub Desktop.
Livewire v3 wire:stream Example
<?php
use Livewire\Component;
class ProgressExample extends Component
{
public function process() {
$progress = 0;
do {
usleep(random_int(8000,100000));
$progress++;
// replace content
$this->stream('a', <<<HTML
<progress value="$progress" max="100" style="width: 50ch">$progress %</progress>
HTML, true);
// append content
$this->stream('b', '.');
} while ($progress < 100);
}
public function render()
{
return <<<'BLADE'
<div>
<button wire:click="process" wire:loading.attr="disabled">start processing</button>
<div wire:stream="b"></div>
<div wire:stream="a"></div>
<div wire:stream="b"></div>
</div>
BLADE;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment