divineomega/laravel-last-activity

Stores the last activity time of users within your Laravel application

v1.1.0 2019-09-30 21:58 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',
    
];