lvlup-dev/laravel-user-last-seen-at 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lvlup-dev/laravel-user-last-seen-at

最新稳定版本:v1.0.0

Composer 安装命令:

composer require lvlup-dev/laravel-user-last-seen-at

包简介

Adds a nullable last_seen_at column on users and middleware to update it on each authenticated request.

README 文档

README

Latest Version on Packagist Total Downloads MIT Licensed

Store a last_seen_at timestamp on your users table and refresh it on each request for authenticated users—useful for “online recently” indicators or light activity tracking without extra tables.

Maintained by Lvlup.

Installation

You can install the package via composer:

composer require lvlup-dev/laravel-user-last-seen-at

Run the migrations (the package registers its migration automatically):

php artisan migrate

Usage

Registering the Middleware

You need to append the middleware to your route groups (e.g., the web group). In Laravel 11+, you can do this in your bootstrap/app.php file:

// bootstrap/app.php
->withMiddleware(function (Illuminate\Foundation\Configuration\Middleware $middleware): void {
    
    // Using the class name...
    $middleware->web(append: [
        \LvlupDev\UserLastSeenAt\Http\Middleware\UserLastSeen::class,
    ]);

    // ...or using the alias registered by this package
    $middleware->web(append: [
        'lastSeenAt',
    ]);
})

Note: Guests are automatically skipped, and no database write occurs for unauthenticated users.

Your User model

This package does not ship a custom User model—you keep yours.

The middleware updates the timestamp using forceFill and saveQuietly. This means:

  1. last_seen_at does not need to be added to your $fillable array.
  2. It will not trigger any updated or saved Eloquent events, saving performance and preventing infinite loops in observers.

You may still want to cast it as a datetime in your User model for convenience:

protected function casts(): array
{
    return [
        'last_seen_at' => 'datetime',
    ];
}

Alternatives

laravel-user-last-seen-at is intentionally minimal: one nullable column and one middleware.

If you need comprehensive audit trails, rich activity feeds, or per-model event history, we recommend using spatie/laravel-activitylog or building a custom event-driven design.

Credits

laravel-user-last-seen-at is built and maintained by LVLUP. We help businesses drive operational efficiency through strategic consulting, tailored software development, and advanced AI Agent integrations.

Read this blog post (in French) on why we built this package to keep activity tracking pragmatic and efficient.

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固