I’ve got some long running methods on my laravel application – some run about 8 minutes. How can I, in Laravel 8 and Livewire 2, setup up an information system which shows a little flash window that e.g. "Step x is done" and Step y is now running?
example:
`public function updateData()
{
$this->updateStatus = 'x wird aktualisiert...';
sleep(2);
$this->updateStatus = 'y wird aktualisiert...';
sleep(2);
$this->updateStatus = 'Alle Daten wurden aktualisiert.';
}`
Livewire never shows me the updateStatus message… 🙁
Where is the best point to start learning about this?
Thank you!
Stev
Ps: also tried to put the above example into pieces: and also didn’t work as expected .. after 14 seconds I see only the finished text thats it…
public function updateData()
{
$this->updateStatus = 'x wird aktualisiert...';
$this->render();
sleep(2);
$this->updateData2();
}
protected function updateData2(){
$this->updateStatus = 'y wird aktualisiert...';
$this->render();
sleep(2);
$this->updateData3();
}
protected function updateData3(){
sleep(10);
$this->updateStatus = 'Alle Daten wurden aktualisiert.';
$this->render();
}
2
Answers
for @ll coming here having the same question and for me :): in your bladefile of your livewire component:
and in your component:
Livewire has good support with alpinejs.
Use Livewire in AlpineJs with $wire
$wire.someMethod(someParam).then(result => { ... })
or you can use
let foo = await $wire.someMethod(someParam)
For more check this https://laravel-livewire.com/docs/2.x/alpine-js
Instead of using
wire:click="updateData"
you ahould useAlso here we run in javascript via alpinejs with $wire and run function sequential with using then then and then .Running updateData() that run other function can’t do here.
You should do something like this