我只是想知道是否有人知道如何在拉维尔判断会话超时.

您可以判断会话是否有特定项目:

if (Session::has('name'))
{
     $name = Session::get('name');
}

But you can't check whether the session has expired. It would be nice so that I can report back to the user in a more specific way. "Your session has timed out, please start again."

Any thoughts?

推荐答案

Just use the same logic as the session class itself.

if ((time() - Session::activity()) > (Config::get('session.lifetime') * 60))
{
   // Session expired
}

Place this in your 'before' filter - and it will run on every request.

Laravel相关问答推荐

发送邮箱后,Laravel重定向偶尔会导致错误500

Laravel本地化错误:"setlocale():参数#1($category)的类型必须是int,给定的是Illuminate\Http\Request"

为什么使用 created_at 表在迁移错误中创建表?

spatie 包 laravel-tags 在迁移中没有 down() 函数是有原因的吗

在部署到 AWS 时保持我的环境参数安全

如何在 Laravel Eloquent Collection 数组之前添加一个键值对?

向 Laravel 模型查询添加计算字段

Laravel:如何强制使用 HTTPS?

判断 Laravel 中是否存在唯一索引键

调用未定义函数 Illuminate\Encryption\openssl_decrypt()

具有实时和 WebSockets 的 Angular2 + Laravel

Laravel Session 总是改变 Laravel 5.4 中的每个刷新/请求

有条件的Eager加载

如何在没有 Eloquent 的情况下创建 Laravel 模型?

如果用户未登录 Laravel,则重定向到登录

我在哪里放置可以显示 Flash 消息的 Laravel 4 辅助函数?

Laravel 检测手机/平板电脑并加载正确的视图

如何判断是否连接到 Laravel 4 中的数据库?

Laravel 数据迁移

找不到 HOME 环境 -- 扩展 `~'