PHPackages                             iresis/login-audit - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. iresis/login-audit

ActiveLibrary

iresis/login-audit
==================

1.0.0(4d ago)01↑2900%MITPHPPHP ^8.3CI passing

Since Jul 25Pushed todayCompare

[ Source](https://github.com/alexandergziresis/login-audit)[ Packagist](https://packagist.org/packages/iresis/login-audit)[ Docs](https://github.com/iresis/login-audit)[ GitHub Sponsors](https://github.com/iresis)[ RSS](/packages/iresis-login-audit/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (12)Versions (2)Used By (0)

Login Audit
===========

[](#login-audit)

 [![Packagist](https://camo.githubusercontent.com/b0ddc2f325df3fd1902af57d53876e0c4ab5ae2f33a2220cba8ca115331c7f32/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6972657369732f6c6f67696e2d61756469742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/iresis/login-audit) [![PHP from Packagist](https://camo.githubusercontent.com/d9eebe7f47641815186140f33450b0fdd6837c0945d79e59ea1d75f45bebb438/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6972657369732f6c6f67696e2d61756469742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/iresis/login-audit) [![Laravel versions](https://camo.githubusercontent.com/1844c8cda8c2a89beb45cfe2c2846d79ad61ae60174ec764217d70272a3eff9c/68747470733a2f2f62616467652e6c61726176656c2e636c6f75642f62616467652f6972657369732f6c6f67696e2d61756469743f7374796c653d666c6174)](https://packagist.org/packages/iresis/login-audit) [![GitHub Workflow Status (main)](https://camo.githubusercontent.com/a54d352030242fcd7e2ce9d74a0c25112ce9587cc6cd41c9046a5132a049fc2f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6972657369732f6c6f67696e2d61756469742f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d5465737473267374796c653d666c61742d737175617265)](https://github.com/iresis/login-audit/actions) [![Total Downloads](https://camo.githubusercontent.com/990358f5750d06f9b10a2b17ae0a018bc33f5bd83b3fd9d6bc4de8a67da8d37c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6972657369732f6c6f67696e2d61756469742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/iresis/login-audit)

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require iresis/login-audit
```

You may publish all of the package's resources at once:

```
php artisan vendor:publish --tag="login-audit"
```

Or, you may publish each resource individually:

### Publishing the Configuration File

[](#publishing-the-configuration-file)

```
php artisan vendor:publish --tag="login-audit-config"
```

### Publishing and Running the Migrations

[](#publishing-and-running-the-migrations)

```
php artisan vendor:publish --tag="login-audit-migrations"
php artisan migrate
```

Usage
-----

[](#usage)

Login Audit listens to Laravel's native authentication events (`Login`, `Logout`, `Failed`, `OtherDeviceLogout`) and records them automatically once installed — no extra wiring required in your login flow.

### What gets recorded

[](#what-gets-recorded)

Every login, logout, failed attempt, and "logout other devices" event is written to the `login_audit_logs` table, along with the resolved IP address, user agent, browser, platform, and device type. Failed attempts store the submitted `email`/`username`/`login` credential as `identifier` (never the password) and, when the credentials matched an existing user, that user's morph reference.

Successful logins also open a row in `login_audit_sessions`, keyed by the framework session ID, which is closed (`logged_out_at`) on logout. This table is the basis for the sessions/devices API below.

### Configuration

[](#configuration)

Toggle what gets tracked, rename tables, swap in your own models, and set retention in `config/login-audit.php`:

```
return [
    'enabled' => true,

    'events' => [
        'login' => true,
        'logout' => true,
        'failed' => true,
        'other_device_logout' => true,
    ],

    'models' => [
        'log' => \Iresis\LoginAudit\Models\LoginAuditLog::class,
        'session' => \Iresis\LoginAudit\Models\LoginAuditSession::class,
    ],

    'retention' => [
        'logs_days' => 90,
        'sessions_days' => 90,
    ],
];
```

### Multi-tenant applications (`tenant_id`)

[](#multi-tenant-applications-tenant_id)

Both tables include a nullable, indexed `tenant_id` column, and both models expose a `forTenant($tenantId)` scope. The package does not resolve the current tenant for you — publish the config and point `models.log`/`models.session` at your own subclasses that fill `tenant_id` (e.g. via a `creating` hook or a global scope tied to your tenancy package of choice):

```
class TenantLoginAuditLog extends \Iresis\LoginAudit\Models\LoginAuditLog
{
    protected static function booted(): void
    {
        static::creating(fn ($log) => $log->tenant_id ??= currentTenantId());
    }
}
```

```
// config/login-audit.php
'models' => [
    'log' => \App\Models\TenantLoginAuditLog::class,
    'session' => \App\Models\TenantLoginAuditSession::class,
],
```

Then scope queries with `LoginAuditLog::forTenant($tenantId)->get()`.

### Sessions and devices

[](#sessions-and-devices)

Add the `HasLoginAudit` trait to your authenticatable model to get convenience relations:

```
use Iresis\LoginAudit\Concerns\HasLoginAudit;

class User extends Authenticatable
{
    use HasLoginAudit;
}

$user->loginAudits;          // all recorded login/logout/failed events for this user
$user->auditSessions;        // all recorded sessions
$user->activeAuditSessions;  // sessions that haven't been logged out
$user->auditDevices();       // sessions grouped by device (browser/platform/device type)
```

The same operations are available through the `LoginAudit` facade or by injecting `Iresis\LoginAudit\LoginAudit`:

```
use Iresis\LoginAudit\Facades\LoginAudit;

LoginAudit::sessionsFor($user);
LoginAudit::activeSessionsFor($user);
LoginAudit::devicesFor($user); // Collection

LoginAudit::revokeSession($session);
LoginAudit::revokeOtherSessions($user, exceptSessionId: $currentSessionId);
```

`revokeSession()`/`revokeOtherSessions()` always mark the audit row as logged out. They can only force-invalidate the underlying framework session (so the device is actually kicked out on its next request) when `SESSION_DRIVER=database`, since that's the only driver this package can reach into from outside that session's own request lifecycle. With other drivers (`file`, `cookie`, `array`, `redis`, ...), only the audit bookkeeping is updated — build your own invalidation on top if you need it (e.g. a "logged out remotely" flag your middleware checks).

> **Note:** Laravel regenerates the session ID during login as session-fixation protection, so the session ID stored in `login_audit_sessions` reflects the *post-login* ID, not the one the browser sent with its login request.

### Keeping "last activity" fresh

[](#keeping-last-activity-fresh)

Apply the `login-audit.activity` middleware alias to routes/groups where you want `last_activity_at` kept up to date (throttled by `login-audit.activity_throttle`, 60 seconds by default):

```
Route::middleware(['auth', 'login-audit.activity'])->group(function () {
    // ...
});
```

### Artisan commands

[](#artisan-commands)

```
# List active sessions (optionally filtered)
php artisan login-audit:sessions
php artisan login-audit:sessions --user=1 --guard=web

# Revoke a specific session
php artisan login-audit:sessions --revoke=

# Prune logs/sessions past their configured retention
php artisan login-audit:prune
```

Schedule pruning in `routes/console.php` if you want it to run automatically:

```
Schedule::command('login-audit:prune')->daily();
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Thank you for considering contributing to Login Audit! Please review our [contributing guide](.github/CONTRIBUTING.md) to get started.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](.github/SECURITY.md) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Alexander](https://github.com/iresis)
- [All Contributors](../../contributors)

License
-------

[](#license)

Login Audit is open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance100

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15112456?v=4)[alexandergz](/maintainers/alexandergz)[@alexandergz](https://github.com/alexandergz)

---

Top Contributors

[![alexandergziresis](https://avatars.githubusercontent.com/u/73916173?v=4)](https://github.com/alexandergziresis "alexandergziresis (3 commits)")

---

Tags

laraveliresislogin-audit

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/iresis-login-audit/health.svg)

```
[![Health](https://phpackages.com/badges/iresis-login-audit/health.svg)](https://phpackages.com/packages/iresis-login-audit)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.3M348](/packages/psalm-plugin-laravel)[api-platform/laravel

API Platform support for Laravel

58174.6k17](/packages/api-platform-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
