Laravel customized session.lifetime at user level

后端 未结 3 1836
刺人心
刺人心 2020-12-05 12:30

I am overwriting session.timeout value in one of the middleware (for Laravel web app) but it doesn\'t seem to be affecting in terms of timing out a session. Tho

3条回答
  •  借酒劲吻你
    2020-12-05 12:42

    The problem occurs because the session has already started, and after that you are changing session lifetime configuration variable.

    The variable needs to be changed for current request, but the user already has a session with lifetime specified.

    You have to change your login method. And do following steps:

    1. See if user exists in database
    2. If yes, and he is user who needs longer session lifetime, run config(['session.lifetime' => 1440]);
    3. log user in

    I recommend using helper to change config on the fly.

    config(['session.lifetime' => 1440]);
    

提交回复
热议问题