aginev / login-activity by aginev

Track users login activity for Laravel 5
9,022
7
2
Package Data
Maintainer Username: aginev
Maintainer Contact: me@aginev.com (Atanas Ginev)
Package Create Date: 2016-02-03
Package Last Update: 2021-10-27
Language: PHP
License: MIT
Last Refreshed: 2024-04-27 03:09:19
Package Statistics
Total Downloads: 9,022
Monthly Downloads: 194
Daily Downloads: 3
Total Stars: 7
Total Watchers: 2
Total Forks: 3
Total Open Issues: 0

Track user login activity in Laravel 5

This package will subscribe for login and logout events and will log data into database or log files.

Features

  • Composer installable
  • PSR4 auto loading
  • Track user login
  • Track user logout
  • Write logs in database or log files
  • Command for cleaning logs

Requires

Build only for Laravel Framework 5 only!

Installation

In terminal

composer require aginev/login-activity:1.0.*

Add Service Provider to your config/app.php like so

// config/app.php

'providers' => [
    '...',
    Aginev\LoginActivity\LoginActivityServiceProvider::class,
];

Publish migrations

php artisan vendor:publish --provider="Aginev\LoginActivity\LoginActivityServiceProvider" --tag="migrations"
php artisan migrate

Optionally you can add login activity command and you will be able to clean your logs.

// app/Console/Kernel.php

protected $commands = [
    '...',
    \Aginev\LoginActivity\Commands\LoginActivityClean::class,
];

Optionally publish config

php artisan vendor:publish --provider="Aginev\LoginActivity\LoginActivityServiceProvider" --tag="config"

Usage

Get logs

$logs = \LoginActivity::getLogs()->get();

Get latest logs

$logs = \LoginActivity::getLatestLogs(100); // number of logs to get or leave empty if you want to use the config value

Get login logs

$logs = \LoginActivity::getLoginLogs()->get();

Get latest login logs

$logs = \LoginActivity::getLatestLoginLogs(100); // number of logs to get or leave empty if you want to use the config value

Get logout logs

$logs = \LoginActivity::getLogoutLogs()->get();

Get latest logout logs

$logs = \LoginActivity::getLatestLogoutLogs(100); // number of logs to get or leave empty if you want to use the config value

Clean log

$logs = \LoginActivity::cleanLog(30); // Offset in days

Clean the log from terminal

php artisan login-activity:clean

Custom handler implmentations

  1. Implement \Aginev\LoginActivity\Handlers\LogActivityInterface in your custom handler.
  2. Place custom handler as value in login-activity.log config

Credits

https://github.com/spatie/activitylog

License

MIT - http://opensource.org/licenses/MIT