edwink/filament-user-activity

Tracks user activity and shows currently active users

1.0.9 2024-04-08 16:03 UTC

This package is auto-updated.

Last update: 2024-10-08 17:21:50 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Filament Active Users

Registers all requests and displays it conveniently to see currently online users, ie. with any requests in the last 15 minutes / 30 minutes / 60 minutes / day / week

Installation

You can install the package via composer:

composer require edwink/filament-user-activity

You can publish and run the migrations with:

php artisan vendor:publish --tag="filament-user-activity-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="filament-user-activity-config"

Optionally, you can publish the views using

php artisan vendor:publish --tag="filament-user-activity-views"

This is the contents of the published config file:

return [
    "table" => [
        "name" => env("FILAMENT_USER_ACTIVITY_TABLE_NAME", "user_activities"),
        "retention-days" => env("FILAMENT_USER_ACTIVITY_RETENTION_DAYS", 60),
        'active-users' => [
            'timeframe-selection' => [
                15 => '15 Minutes',
                30 => '30 Minutes',
                60 => 'One hour',
                120 => '2 Hours',
                1440 => '24 hours',
            ],
        ],
    ]
];

Usage

Add Global Middleware in app/Http/Kernel.php

    /**
     * The application's global HTTP middleware stack.
     *
     * These middleware are run during every request to your application.
     *
     * @var array<int, class-string|string>
     */
    protected $middleware = [
        ...
        \Edwink\FilamentUserActivity\Http\Middleware\RecordUserActivity::class,
    ];

Add trait to User Model app/Models/User.php to add relationship activities

use Edwink\FilamentUserActivity\Traits\UserActivityTrait;
...

class User extends Authenticatable
{
    use UserActivityTrait;
    ...
}

Configure your panel to have 2 additional views

use Edwink\FilamentUserActivity\FilamentUserActivityPlugin;

...
public function panel(Panel $panel): Panel
{
    return $panel
        ...
        ->plugins([
           FilamentUserActivityPlugin::make()
        ])
        ...
}
...

Configure a scheduled task to truncate table depending on your configured days (default 60 days) or run it manually from time to time.

php artisan filament-user-activity:truncate-activities-table

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.