Sending updates to livewire elements on database change
I've built a cart element using livewire that is attached to my top menu bar and am attempting to send real-time updates to the element to show when items are added or removed from the cart.
My current method of deploying the element to the layout is with a render hook
This works for displaying items in the cart, but any changes from an action or from the cart itself do not display real-time changes, I'd like to change this behavior if I can. What is my best move forward?
Thank you for your time
Solution:Jump to solution
Thank you for the comment, sorry for the delay, been a very busy week!
I figured it out. I was already emitting updates, but it turns out my render function was not passing the updated variable (see below) in the livewire function. Adding it there fixed it immediately. Thanks for your feedback!
```public function render()...
4 Replies
You could make this a Livewire component and then dispatch a Livewire event to fetch some updates when you update data related to the cart
I’ve attempted that, was not successful. Can you provide a good resource to look at for this? My efforts don’t seem to be successful
I’ve attempted that, was not successfulMaybe share some code and tell us what didn't work. I mean for real time changes you need something like Websockets. Do you really need this? I think it's enough to update the cart when the current users updates stuff, right?
Solution
Thank you for the comment, sorry for the delay, been a very busy week!
I figured it out. I was already emitting updates, but it turns out my render function was not passing the updated variable (see below) in the livewire function. Adding it there fixed it immediately. Thanks for your feedback!