Laravel: create a temporary session for guest user and delete the session when he closes the website tab
In Laravel, if user come from a specific link, I have to show him some different menu items, for that particular session, until he closes the browser tab or windows of website.
Is there any way to achieve this in Laravel. Can I achieve this by using session?
You cannot delete the session based on closing the tab, because the browser doesn't notify the server that it got closed.
I've done this once in the past by sending a request to the backend every 30 seconds to keep the session alive. If the server doesn't get a new response it removed the session after 1 minute automatically using a scheduled task that runs every minute.
You can put something in the user's session that says they are viewing the alternate menu. When they go away , their session will expire. You cannot force it to expire because you don't know they have gone away.
You can set the session cookie to expire when they close their browser, but that is just a flag on the cookie you send them and they are not forced to close the browser.