Sounds like you want to set it in mount(). Then it gets loaded once when the component is loaded.
Sep 26, 2022
4
Level 2
Livewire + Firebase-PHP - variable doesnt get passed from one function to the other
From title, how do I pass QuerySnapshot variable from render() into another function? I tried json_encode'ing into front end but it doesnt work, so my next option is to save it in a private variable and attempt to use it rather than calling Firebase transaction again.
Livewire class
private QuerySnapshot $results;
public function render() {
// other code redacted
$queryRes = $this->db->collection('collection-to-find');
if(!$this->error) {
if($this->searchString)
$queryRes = $queryRes->where('filter', '==', $this->searchString)->documents();
else {
$queryRes = $queryRes->documents();
}
}
$this->results = $queryRes; //save it to QuerySnapshot $results
return view(' <redacted> ');
}
public function download() // the supposed receiving function after pressing the front-end livewire button
{
dd($this->results); // this returns null
// this will return Excel::download with $this->results as the parameter to it.
}
Please or to participate in this conversation.