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

garrettmassey's avatar

Laravel 6 set a cookie that lasts forever at the start of an authenticated session.

I want to store a cookie that has a value that is equal to the app's version number, and do the following:

  1. when a user is authenticated, check to see if the cookie exists
  2. if the cookie does not exist, create it
  3. if the cookie exists, check the value and compare it against a DB value
  4. if the DB value is greater than the cookie value, it means the app has updated, then show an update notification that links to the latest doc.
  5. Keep the cookie value the same until the user has acknowledged the notification, then update the cookie to be equal to the DB value.

I can handle the logic for steps 3 and 4, but what I am having a hard time figuring out is how check for the cookie when a user logs in, and how to create it to last forever if the cookie doesn't already exist.

Any help is greatly appreciated!

0 likes
5 replies
Snapey's avatar
Snapey
Best Answer
Level 122

why not just a version number column on the users table?

that way, it does not matter which device they use.

garrettmassey's avatar

@Snapey So a version number column on the user table that stores the version number they last used, and compares it to the current version number, and if they are the same, then no update, if the current version number is > user_version it means there has been an update.

Is that the thought process behind it?

Snapey's avatar

with cookies the user is going to see that update notice on every device, and if they delete their cookies or have a new machine, then they are back at version 1 and get every notice...

1 like

Please or to participate in this conversation.