Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

iamlux20's avatar

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.
}
0 likes
4 replies
Sinnbeck's avatar

Sounds like you want to set it in mount(). Then it gets loaded once when the component is loaded.

iamlux20's avatar

@Sinnbeck trying to set it in mount as new QuerySnapshot however it needs the document details which doesnt load until user submits the form. will edit the render in question to suit more needs

Sinnbeck's avatar

@iamlux20 Just tested it. Livewire can only hydrate it if its a public property. So you will need to add some sort of helper method you can call each time (or duplicate the code in download()). Remember that its a new call to php each time, so livewire needs to build the class with all the data each time

1 like
iamlux20's avatar

@Sinnbeck seems like it would get trickier than repeating the transaction. might stick to two firebase calls (render and download)

Please or to participate in this conversation.