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

rudolfbruder's avatar

Private and Protected properties in Livewire

Hi Guys,

Please let me know if I understand it and I am using it correctly.

I use private / protected properties for livewire components when these props do not need to be fetched / rehydrated on every re-render of the component. This leads to significant perfomance boost because these queries are only fetched once in the mount() method where they are in best case put into Cache. Why in mount? Because some other methods in mount might depend on the data.

Then when I am passing the properties in render method to view like this:

    public function render()
    {
        $this->getOtherColors();
        return view('livewire.' . eshop()->getViewPath() . '.colored-product.colored-product-panel', ['otherColors' => $this->otherColors]);
    }

I still need to call the $this->getOtherColors() method - which is just and Cache::remember and simple query for model all let's say - it does not matter.

My questions are: Is that correct? How to avoid the need to call it on each render? Is the solution to make custom hydrateOtherColors method and make it public - in this method just fetch it from cache?

0 likes
5 replies
vincent15000's avatar

What are the public, private and protected properties in your component ?

rudolfbruder's avatar

@webrobert Ok what is the benefit? Logic in computed should include Cache::remember(logic) right? Even though it's cached for each lifecycle. My point is that I dont want to ping DB on every request.

1 like
webrobert's avatar

@rudolfbruder

you certainly can use Cache with a computed property.

public function getOtherColorsProperty()
{
	// return Cache::remember(logic);
}

They are kind of apples and oranges. For your use case you'd be using Cache whether you were using livewire or not.

1 like

Please or to participate in this conversation.