0

如何在 48 小时后注销用户。

public function generatePass(Request $request)
{
    $myRandomString = Str::random(8);
    
    DB::table('web_passes')->insert([
        'pass' => $myRandomString,
        'user_id' => $request->user_id,
        'expiry_time' =>   Carbon::now()->addDays(2)
    ]);
4

2 回答 2

0

你可以改变SESSION_LIFETIME=20.env

本例中会话的生命周期为 20 分钟

所以在任何请求中都应该授权给它

if(auth()->check())完成执行

else

删除或将令牌引用为无效并重定向到登录页面

于 2022-01-10T09:52:44.977 回答
0

我只是通过简单地应用中间件条件来做到这一点

 public function handle(Request $request, Closure $next)
    {
        $webPass = $request->user()->webPass;
        if($webPass->expiry_time < Carbon::now()){
            $randomString = str::random(8);
            $webPass->pass = $randomString;
            $webPass->expiry_time = Carbon::now()->addSeconds(30);
            $webPass->update();
            Auth::logout();
            return redirect('/otp')->with('expiry_time', 'Your session has expired');
        }
        return $next($request);
    }
于 2022-01-10T10:31:58.223 回答