Created
February 19, 2024 15:53
-
-
Save nuernbergerA/5a328de091d700317cf983573c0ab22f to your computer and use it in GitHub Desktop.
Livewire v3 wire:stream Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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