I just solved a part of the problem.
Here is the whole Livewire component.
public $products;
public function mount(ProductService $productService)
{
$this->products = collect($productService->getProducts())->map(function ($product) {
return [
'id' => $product['id'],
'name' => $product['name'],
'price' => $product['prices'][0]['price'],
];
});
}
public function render()
{
return view('livewire.products-page');
}
If $products is a public property, the error is generated.
But if I change the code to this, I don't get any error and the page loads fine. But it loads only when the datas are loaded, that means that lazy loading doesn't work.
public function render()
{
$products = collect((new ProductService)->getProducts())->map(function ($product) {
return [
'id' => $product['id'],
'name' => $product['name'],
'price' => $product['prices'][0]['price'],
];
});
return view('livewire.products-page', compact('products'));
}
But I'm quite sure that if I want lazy loading, I need the first version of the code with a public property, because in the last version, the getProducts() method (which calls an third-party API) stops the code execution and the view is returned only when the datas are retrieved.
Can you confirm my analysis ?