I have a function that makes a few requests to external APIs and takes a little long to finish.
I have a status variable in my livewire component and a poll component updating it in the view, and it works fine.
During the function execution, however, I have a foreach and update the status variable with the progress every iteration, but the frontend stops sending the update ajax to the server, and the progress is not displayed.
How can I make the status update work during the function execution? Any help will be appreciated.
Page:
<x-filament-panels::page wire:poll.750ms="getStatus">
<form wire:submit.prevent='generate'>
{{ $this->form }}
<x-button type="submit" class="mt-4">
Submit
</x-button>
</form>
<div >
{{ $this->getStatus() }}
</div>
</x-filament-panels::page>
Component:
public $status = 'Ready to start!';
public function updateStatus($message){
$this->status = $message;
}
public function getStatus(){
return $this->status . time();
}
public function generate(){
// Not relevant code
foreach (json_decode($result->choices[0]->message->content) as $key=>$person){
$this->updateStatus('Generating ' . $key. ' of ' . $amount . '.');
}
// Not relevant code
}
Im using Livewire 3 with Filament.