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

Gks's avatar
Level 1

Persist data with Laravel and Livewire

I am currently learning Laravel with Livewire and working on a time tracking system. I am encountering a challenge where I need to persist the time that a user stops when they reload the page. Currently, I have a clock that can start and stop, but I want to ensure that the time continues from where the user left off after a page reload.

The time is stored in a database, but I'm unsure how to retrieve the correct time and display it on the screen after a page reload. Could anyone provide some guidance or ideas on how to implement this?

When a user initiates a timer, it gets stored in the database. One approach I considered was retrieving the most recent timer for the user that lacks a final time. Another thought was to store the time in local storage, but I believe this may not be the optimal solution.

0 likes
3 replies
Gks's avatar
Level 1

@vincent15000 An example of this functionality can be seen in the software, Clockify [clockify.me]. If I start the timer at 00:00:00, then close the page, and return after 30 seconds, the timer will display 00:00:30. The mechanism behind this feature is beyond my understanding.

1 like
vincent15000's avatar

@Gks I never coded any time tracker, but according to me have 2 ways to do that :

  • save the start time in the session, but if the user log out, you will lose this information

  • save the start time in the local storage, but if the user empties the browser cache, you will lose this information

If you want to keep the information, the only way is to store it in the database, or to cache it (even if the cache is not dedicated to do that).

2 likes

Please or to participate in this conversation.