Laravel 4 Remember me expire time

前端 未结 1 717
鱼传尺愫
鱼传尺愫 2020-12-29 10:24

I am fairly new to Laravel and had a question regarding the remember me function.

I have successfully enabled the \"remember me\" function by attaching a second argu

相关标签:
1条回答
  • 2020-12-29 11:02

    I don't know whether its a good way to do it or not, but if you are desperate to set the expiration time for remember me you can try this, it works for me though.

    Let the laravel's Auth::atempt($credential,true) do its normal business, i.e, setting the remember me expiration time to 5 years

    We will change this in App::after() method, so in your filters.php file find App::after() method and change the cookie expiration time

    App::after(function($request, $response)
    {
      if ( Auth::check()){
          $ckname=Auth::getRecallerName(); //Get the name of the cookie, where remember me expiration time is stored
          $ckval=Cookie::get($ckname); //Get the value of the cookie
          return $response->withCookie(Cookie::make($ckname,$ckval,360)); //change the expiration time
      }
    });
    

    Note: Cookie::make('name','value','expiration time');

    0 讨论(0)
提交回复
热议问题