PHPackages                             zaichaopan/online-status - 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. [Caching](/categories/caching)
4. /
5. zaichaopan/online-status

ActiveLibrary[Caching](/categories/caching)

zaichaopan/online-status
========================

A package to show user online status in your laravel app

v0.2-beta(7y ago)374[1 PRs](https://github.com/zaichaopan/online-status/pulls)MITPHPPHP &gt;=7.1.0

Since Jun 21Pushed 4y ago1 watchersCompare

[ Source](https://github.com/zaichaopan/online-status)[ Packagist](https://packagist.org/packages/zaichaopan/online-status)[ RSS](/packages/zaichaopan-online-status/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

Online Status
=============

[](#online-status)

This packages adds functionality to show user online status, online users and online user number in your laravel app. This package can be used in **laravel 5.5 or higher**.

Installation
------------

[](#installation)

This packages uses **redis** behind the screen. So please install redis in your machine in order to use package.

```
composer require zaichaopan/online-status
```

Usage
-----

[](#usage)

- Add **HasOnlineStatus** trait to your user model

```
//...
use Zaichaopan\OnlineStatus\HasOnlineStatus;

class User extends Model
{
    use HasOnlineStatus;

}
```

- Set online expiration time.

This package uses **lifetime** in **config/session.php** as the default user online expiration time. If user remains inactive during this time period, he or she will be considered offline. So if you want to customize. you can override it in **config/session.php** or you can override it in User model as follow

```
// ...
class User extends Model
{
    use HasOnlineStatus;

    public static function getOnlineExpirationInMinutes(): int
    {
        return 10;
    }
}
```

- Apply **UserOnline** Middleware.php

```
// App\Http\Kernel.php
class Kernel extends HttpKernel
{
    // ...
    protected $middlewareGroups = [
        'web' => [
           \\...
           \Zaichaopan\OnlineStatus\Middleware\UserOnline::class
        ],
        //...
    ];
}
```

Now when authenticated user makes a web request, his or her online status will be automatically be set.

```
//
class UserOnline
{
   // ...
    public function handle(Request $request, Closure $next)
    {
        optional($request->user())->online();

        return $next($request);
    }
}
```

Available Apis
--------------

[](#available-apis)

- Get whether user is online:

```
$status = $user->isOnline;

// or
$status = $user->isOnline();
```

- Get total online user number

```
$onlineUserCount = User::onlineCount();
```

- Get online users

```
$onlineUsers = User::ofOnline()->get();

// or
$onlineUsers = User::ofOnline()->paginate();
```

- Set user online

As long as you apply the **UserOnline** middleware properly, it will automatically set and update authenticated user online status. In case you want to set it manually, you can use **online** method provided by the trait.

```
$user->online();
```

- Set user offline

This package listens for **Logout** event. When user logs out, it will set user online status as offline. In case you may want to set user offline manually, you can use **offline** method provided by the trait.

```
$use->offline();
```

Events
------

[](#events)

This packages raises two events during the updating user online status process. You may attach listeners to these two events in your EventServiceProvider:

```
/**
 * The event listener mappings for the application.
 *
 * @var array
 */
protected $listen = [
    'Zaichaopan\OnlineStatus\Events\Online' => [
        'App\Listeners\Online',
    ],

    'Zaichaopan\OnlineStatus\Events\Offline' => [
        'App\Listeners\Offline',
    ]
];
```

The **Online** event will only fire once. It won't fire again if the user is already online

###  Health Score

23

—

LowBetter than 30% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

2

Last Release

2830d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5dfb2782ff22c81ce8095946983c3d437156ed09b132ec93727da68a14fa7db0?d=identicon)[zaichaopan](/maintainers/zaichaopan)

---

Top Contributors

[![zaichaopan](https://avatars.githubusercontent.com/u/16104572?v=4)](https://github.com/zaichaopan "zaichaopan (8 commits)")

---

Tags

laravelonlineredislaravelredisonline

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zaichaopan-online-status/health.svg)

```
[![Health](https://phpackages.com/badges/zaichaopan-online-status/health.svg)](https://phpackages.com/packages/zaichaopan-online-status)
```

###  Alternatives

[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

981161.4k2](/packages/awssat-laravel-visits)[monospice/laravel-redis-sentinel-drivers

Redis Sentinel integration for Laravel and Lumen.

103826.2k](/packages/monospice-laravel-redis-sentinel-drivers)[encore/redis-manager

Redis manager for laravel

25243.1k](/packages/encore-redis-manager)[vetruvet/laravel-phpredis

Use phpredis as the redis connection in Laravel

45122.8k](/packages/vetruvet-laravel-phpredis)[ginnerpeace/laravel-redis-lock

Simple redis distributed locks for Laravel.

16112.7k](/packages/ginnerpeace-laravel-redis-lock)[craftsys/laravel-redis-session-enhanced

Enhanced redis driver for sessions in Laravel

106.2k](/packages/craftsys-laravel-redis-session-enhanced)

PHPackages © 2026

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