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

Maddox's avatar

Do something when session expire.

Hello guys, I just wanna know if it's possible to update a table on the DB when the session lifetime expire ?

0 likes
6 replies
d3xt3r's avatar
d3xt3r
Best Answer
Level 29

As in from where ???

Schedule a job that does that, if you really need.

Maddox's avatar

Well, it's kinda easy, I have a website, a client can add an article into the cart. When he add it, the "stock" is directly reduced in the DB, and when he manually remove it from the cart, the article is added back into the DB. (Just talking about the stock that's available for the article).

Now the problem, it's that the library that I use for my cart (https://github.com/Crinsane/LaravelShoppingcart), add the cart articles in the default session of laravel, and the default session lifetime (for Laravel) is 60 minutes, then the session is automatically erased and I can't update my DB with the correct quantity. (the articles are just lost in the void ;( ).

Can help me with Jobs ? I never used them before.

Thanks for the help :)

jlrdw's avatar

Re program things where stock isn't update until a confirm or whatever is clicked.

d3xt3r's avatar

Sorry, never used the package myself and no idea what is it doing. I will try to look at the package, and explore how it handles expired session ... but as of now don't know ...

Maddox's avatar

Yeah but the problem is that the owner of the website, want that the article is "reserved" just when he add it into the cart, so I must do something like that.

array:5 [▼
  "_token" => "xUNCgiIOGqHW7AsMX5OKsBPyK9SvA8pP4vYKF3gn"
  "_previous" => array:1 [▶]
  "flash" => array:2 [▶]
  "login_web_59ba36addc2b2f9401580f014c7f58ea4e30989d" => 2
  "cart" => array:1 [▼
    "main" => CartCollection {#207 ▼
      #items: array:1 [▼
        "6dfbd6f97e12081ec819ea0645f9c49c" => CartRowCollection {#208 ▼
          #associatedModel: null
          #associatedModelNamespace: null
          #items: array:7 [▼
            "rowid" => "6dfbd6f97e12081ec819ea0645f9c49c"
            "id" => "7"
            "name" => "Château La Lagune 1995"
            "qty" => "1"
            "price" => "60"
            "options" => CartRowOptionsCollection {#209 ▶}
            "subtotal" => 60
          ]
        }
      ]
    }
  ]
]

The "cart" item in the session, it's what is added by the library :)

nscott's avatar

Hey @maddox wondering if you ever figured this one out. I am having some issues with the same thing now and trying to figure out the best solution for it.

Please or to participate in this conversation.