I have sideBar menu I put into it the products in cart for each user so I did the normal way, the query inside render method and foreach then in blade component, but when check the debggbar I see there is query once the page opened! So I need when the side bar is opened render the data otherwise don’t render it
there is a button to open the side bar:
<button
wire:click="addToCart"
class="btn btn-success add-to-cart"
>
add_to_cart
</button>
class SlideCart extends Component
{
protected $listeners = [
'slideCart:update' => '$refresh',
];
public function removeProduct($id){
user()->cart()->detach($id);
}
public function render()
{
$products = user()->cart()->mainImage()->get();
return view('livewire.user.slide-cart',compact('products'));
}
}