0

I have a livewire component called Cart.

If the user open this component in multiple devices at the same time (i.e. mobile and desktop, or open it in multiple browser tabs), and add an item to the cart in the mobile browser, is there a way to refresh the component in desktop browser?

I know these components are independent of each other, so I'm thinking of a solution where I have to store, for example, the component ID (or something like that) and create the another one based on it.

Is there a well-developed solution to this?

fff
  • 402
  • 3
  • 10
  • 1
    To refresh a remote instance, you need to either poll to continuously check for updates, or you can use a websocket to broadcast an event - I have previously posted [an answer](https://stackoverflow.com/questions/64186425/how-to-refresh-the-component-after-the-queue-job-is-finished/64187267#64187267) about this which you can use for reference. The items in the cart needs to be stored in the database, so they can be retreived regardless of sessions. – Qirel Jan 28 '21 at 18:32

1 Answers1

1

I'm not aware of any existing solution like this but you could save the cart in DB and then retrieve it for all your platforms. To make it so it's always synced on both platforms you could build your mobile application on APIs or otherwise use something like the Broadcasting within Laravel or a package like Laravel WebSockets.

Livewire is more for building dynamic interfaces removing the complexity of making AJAX requests in the background and doesn't support multiple platforms the way you are wanting.

ByWaleed
  • 395
  • 4
  • 18
  • Thanks, I think you're right, but before I accept your answer, I'll wait a bit, maybe someone has a solution to this problem. – fff Jan 28 '21 at 17:56
  • i think it's time to start for the next task – fff Jun 28 '21 at 22:43