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.

Maintainers

Package info

github.com/lvlup-dev/laravel-user-last-seen-at

Homepage

Documentation

Type:laravel-package

pkg:composer/lvlup-dev/laravel-user-last-seen-at

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-03-29 13:05 UTC

This package is auto-updated.

Last update: 2026-03-29 13:06:13 UTC


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.