lopatin96/laravel-user-online

Laravel user online

1.0.1 2024-02-29 15:44 UTC

This package is auto-updated.

Last update: 2024-11-29 17:10:57 UTC


README

Migrations

Run migrations to create the necessary tables.

php artisan migrate

Middleware

Add LastUserActivity middleware to middleware array in app/Http/Kernel.php:

protected $middlewareGroups = [
    …
    \Atin\LaravelUserOnline\Http\Middleware\LastUserActivity::class,
];

Trait

You cant optionally add HasOnline trait to User model to get the online status of the user.

use Atin\LaravelUserOnline\Traits\HasOnline;

class User extends Authenticatable
{
    use HasOnline, …

don't forget to cast last_seen_at property to datetime in your User model:

protected $casts = [
    …
    'last_seen_at' => 'datetime',
];

and then you can check the online status:

auth->user()->isOnline();

Publishing

Migrations

php artisan vendor:publish --tag="laravel-user-online-migrations"

Config

php artisan vendor:publish --tag="laravel-user-online-config"