PHPackages                             taldres/laravel-last-seen - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. taldres/laravel-last-seen

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

taldres/laravel-last-seen
=========================

Laravel package to track user's last seen status.

v0.3.1(9mo ago)1287[2 PRs](https://github.com/Taldres/laravel-last-seen/pulls)MITPHPPHP ^8.2CI passing

Since Jul 25Pushed 5mo agoCompare

[ Source](https://github.com/Taldres/laravel-last-seen)[ Packagist](https://packagist.org/packages/taldres/laravel-last-seen)[ RSS](/packages/taldres-laravel-last-seen/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (9)Versions (10)Used By (0)

[![Packagist Version](https://camo.githubusercontent.com/068668214f9da11ec0a8c0494db40e2dec070bc2009e89638884203d948f8499/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f74616c647265732f6c61726176656c2d6c6173742d7365656e)](https://packagist.org/packages/taldres/laravel-last-seen)[![Tests](https://github.com/Taldres/laravel-last-seen/actions/workflows/run-tests.yml/badge.svg)](https://github.com/Taldres/laravel-last-seen/actions/workflows/run-tests.yml/badge.svg)

Laravel Last Seen
=================

[](#laravel-last-seen)

A simple Laravel package to track a user's last seen and recently seen status. This package provides traits, middleware, events, and configuration to easily record and query when a user was last active in your Laravel application.

Features
--------

[](#features)

- Automatically update the `last_seen_at` timestamp for users
- Middleware to detect user activity
- Event-based architecture for extensibility
- Query scopes and helper methods to check if a user was recently seen
- Configurable thresholds for updating and checking activity
- Migration publishing for easy setup

Requirements
------------

[](#requirements)

### PHP

[](#php)

PHP 8.2 or higher

### Supported Laravel Versions

[](#supported-laravel-versions)

Laravel VersionPackage Version`^11.15``^0.2``^12.0``^0.2`Installation
------------

[](#installation)

1. Install the package via Composer:

    ```
    composer require taldres/laravel-last-seen
    ```
2. Publish the migration and configuration files:

    ```
    php artisan vendor:publish --provider="Taldres\LastSeen\LastSeenServiceProvider"
    ```
3. Clear the configuration cache to ensure the new settings are loaded:

    ```
    php artisan optimize:clear
    # or
    php artisan config:clear
    ```
4. Run the migration to create the necessary database table:

    ```
    php artisan migrate
    ```
5. Add the `Taldres\LastSeen\Trait\LastSeen` trait to your User model:

    ```
    use Taldres\LastSeen\Trait\LastSeen;

    class User extends Authenticatable
    {
        use LastSeen;
        // ...
    }
    ```
6. Add the middleware to your `web` or `api` middleware group or any other endpoint:

    ```
    // ...
    \Taldres\LastSeen\Middleware\UpdateLastSeenMiddleware::class,
    // ...
    ```

Configuration
-------------

[](#configuration)

If necessary or in case of a newer version, you can publish the configuration file to customize the package settings:

```
php artisan vendor:publish --provider="Taldres\LastSeen\LastSeenServiceProvider" --tag="config"
```

or this command to force overwrite the existing configuration file:

```
php artisan vendor:publish --provider="Taldres\LastSeen\LastSeenServiceProvider" --tag="config" --force
```

---

In the `config/last-seen.php` file, you can specify the User model to be used for tracking last seen timestamps:

- `user`: The fully qualified class name of the User model to be used for tracking last seen timestamps.

All other settings—such as enabling/disabling the feature, update thresholds, and recently seen thresholds—can be controlled via environment variables in your `.env` file:

- `LAST_SEEN_ENABLED`: Enables or disables the package globally (default: true). It affects only the `updateLastSeenAt` method and the middleware.
- `LAST_SEEN_UPDATE_THRESHOLD`: Minimum seconds between last\_seen\_at updates (default: 60)
- `LAST_SEEN_RECENTLY_SEEN_THRESHOLD`: Seconds a user is considered recently seen after last activity (default: 300)

Each setting has a default value, so you only need to override them if you want to change the default behavior.

Usage
-----

[](#usage)

### Checking Activity

[](#checking-activity)

- `$user->recentlySeen()`: Returns `true` if the user was active within the configured threshold.
- `User::onlyRecentlySeen()`: Query scope to get only users recently seen.

### Events

[](#events)

The package fires a `UserWasActiveEvent` whenever user activity is detected. You can listen to this event for custom logic.

### Manually Dispatching the Event

[](#manually-dispatching-the-event)

You can also dispatch the `UserWasActiveEvent` from your own application code:

```
use Taldres\LastSeen\Events\UserWasActiveEvent;
use Illuminate\Support\Facades\Event;

Event::dispatch(new UserWasActiveEvent($user));
```

License
-------

[](#license)

MIT

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance65

Regular maintenance activity

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

6

Last Release

279d ago

PHP version history (2 changes)v0.1.0PHP &gt;=8.3

v0.2.2PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/447342a2b11f3ca024a0b1e864b83cdf00b943f5a054c4c4f6b3140c00d13d82?d=identicon)[Taldres](/maintainers/Taldres)

---

Top Contributors

[![Taldres](https://avatars.githubusercontent.com/u/648266?v=4)](https://github.com/Taldres "Taldres (47 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/taldres-laravel-last-seen/health.svg)

```
[![Health](https://phpackages.com/badges/taldres-laravel-last-seen/health.svg)](https://phpackages.com/packages/taldres-laravel-last-seen)
```

###  Alternatives

[laragear/two-factor

On-premises 2FA Authentication for out-of-the-box.

339785.3k8](/packages/laragear-two-factor)[casbin/laravel-authz

An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel.

324339.9k4](/packages/casbin-laravel-authz)[yajra/laravel-acl

Laravel ACL is a simple role, permission ACL for Laravel Framework.

112103.9k1](/packages/yajra-laravel-acl)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

44643.1k1](/packages/pressbooks-pressbooks)[scaler-tech/laravel-saml2

SAML2 Service Provider integration for Laravel applications, based on OneLogin toolkit

2737.5k](/packages/scaler-tech-laravel-saml2)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
