divineomega/laravel-last-activity

Stores the last activity time of users within your Laravel application

v1.3.0 2021-01-27 21:59 UTC

This package is auto-updated.

Last update: 2024-10-28 06:24:30 UTC


README

Stores the last activity time of users within your Laravel application

Installation

To install the Laravel Last Activity package, just run the following Composer command from the root of your project.

composer require divineomega/laravel-last-activity

Setup

This package requires you to register middleware within your app\Http\Kernel.php file. You will need add the middleware to every middleware group you wish to monitor activity for, as shown below.

protected $middlewareGroups = [
        'web' => [
            /* ... other web middleware ... */
            \DivineOmega\LaravelLastActivity\Http\Middleware\LastActivity::class
        ],

        'api' => [
            /* ... other api middleware ... */
            \DivineOmega\LaravelLastActivity\Http\Middleware\LastActivity::class
        ],
    ];

You also need to add the config file and migration to your project. To do so, simply run the following Artisan command.

php artisan vendor:publish --provider="DivineOmega\LaravelLastActivity\ServiceProvider"

You can then run the provided migration to add a last_activity field to your users table.

php artisan migrate

That's it. The last_activity field within your users will be automatically updated whenever the user interacts with your application via the web or API.

Alternative field name

If you do not wish to use last_activity as the field name, this can be changed in the provided migration. You will also need to alter the configuration file

The published configuration file for this package can be found at config/last-activity.php.

<?php

return [
    
    // Field in which the last activity date time will be stored.
    'field' => 'last_activity',
    
];