lvlup-dev/laravel-user-last-seen-at
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.
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
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.
User modelThis package does not ship a custom User model—you keep yours.
The middleware updates the timestamp using forceFill and saveQuietly. This means:
last_seen_at does not need to be added to your $fillable array.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',
];
}
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.
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.
The MIT License (MIT). Please see License File for more information.
How can I help you explore Laravel packages today?