PHPackages                             codebyray/laravel-auth-log - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. codebyray/laravel-auth-log

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

codebyray/laravel-auth-log
==========================

Log user authentication details and send new device notifications.

v1.0.0(3y ago)1129MITPHPPHP ^8.0

Since Sep 30Pushed 3y ago1 watchersCompare

[ Source](https://github.com/codebyray/laravel-auth-log)[ Packagist](https://packagist.org/packages/codebyray/laravel-auth-log)[ Docs](https://github.com/codebyray/laravel-auth-log)[ RSS](/packages/codebyray-laravel-auth-log/feed)WikiDiscussions main Synced 1w ago

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

Laravel Auth Log is a package which tracks your user's authentication information such as login/logout time, IP, Browser, Location, etc. as well as sends out notifications via mail, slack, or sms for new devices and failed logins.

Documentation, Installation, and Usage Instructions
---------------------------------------------------

[](#documentation-installation-and-usage-instructions)

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

[](#installation)

Installing the package via composer:

```
composer require codebyray/laravel-auth-log
```

If you want to use the location features you will need to install `torann/geoip`

```
composer require torann/geoip
```

If you choose to install `torann/geop` you should publish the config file:

```
php artisan vendor:publish --provider="Torann\GeoIP\GeoIPServiceProvider" --tag=config
```

Setup / Configuration
---------------------

[](#setup--configuration)

Publish and run the migrations:

```
php artisan vendor:publish --provider="Codebyray\LaravelAuthLog\LaravelAuthLogServiceProvider" --tag="auth-log-migrations"
php artisan migrate
```

Publish views and email files:

```
php artisan vendor:publish --provider="Codebyray\LaravelAuthLog\LaravelAuthnLogServiceProvider" --tag="auth-log-views"
```

Publish the config file:

```
php artisan vendor:publish --provider="Codebyray\LaravelAuthLog\LaravelAuthLogServiceProvider" --tag="auth-log-config"
```

Config file contents:

```
return [

    /*
    |--------------------------------------------------------------------------
    | Database Table Name
    |--------------------------------------------------------------------------
    |
    | You can change the database table name if you wish. For most cases this
    | does not need to be modified
    |
    */
    'table_name' => 'auth_log',

    /*
    |--------------------------------------------------------------------------
    | Database Connection
    |--------------------------------------------------------------------------
    |
    | This is the connection to the database at which the auth_log table resides.
    | Leave this as null to use your applications default database connection.
    |
    */
    'db_connection' => null,

    /*
    |--------------------------------------------------------------------------
    | Events Listened For
    |--------------------------------------------------------------------------
    |
    | These are the events this package will listen for and log.
    |
    */
    'events' => [
        'login' => \Illuminate\Auth\Events\Login::class,
        'failed' => \Illuminate\Auth\Events\Failed::class,
        'logout' => \Illuminate\Auth\Events\Logout::class,
        'logout-other-devices' => \Illuminate\Auth\Events\OtherDeviceLogout::class,
    ],

    /*
    |--------------------------------------------------------------------------
    | Notifications Configuration
    |--------------------------------------------------------------------------
    |
    | This is where we setup the notifications that are sent out.
    |
    | new-device
    |   enabled
    |       - If enabled is set to true, a notification will be sent when a user logs
    |         in with a new device.
    |   location
    |       - If set to true, the location of the user will be sent with the notification.
    |         Notice: You must have installed torann/geoip for this to work.
    |   template
    |       - The notification class iused to send the notification.
    |
    | failed-login
    |   enabled
    |       - If enabled is set to true, a notification will be sent when a user login
    |         has failed.
    |   location
    |       - If set to true, the location of the user will be sent with the notification.
    |         Notice: You must have installed torann/geoip for this to work.
    |   template
    |       - The notification class iused to send the notification.
    |
    */
    'notifications' => [
        'new-device' => [
            'enabled' => env('AUTH_LOG_NEW_DEVICE_NOTIFICATION', true),
            'location' => env('AUTH_LOG_GET_LOCATION', false),
            'template' => \Codebyray\LaravelAuthLog\Notifications\NewDevice::class,
        ],
        'failed-login' => [
            'enabled' => env('AUTH_LOG_FAILED_LOGIN_NOTIFICATION', true),
            'location' => env('AUTH_LOG_GET_LOCATION', false),
            'template' => \Codebyray\LaravelAuthLog\Notifications\FailedLogin::class,
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Purge (Clean-up) Logs
    |--------------------------------------------------------------------------
    | purge
    | When the clean-up command is run, this will determine how old the logs must be
    | in order to be deleted. Set purge days to the number of days you wish to keep
    | the logs. If you would like to keep them indefinitly, do not schedule the clean-up
    | command to run.
    |
    */
    'purge' => 365,
];
```

Setup The User Model
--------------------

[](#setup-the-user-model)

In order to log the events above you need to add the `AuthenticationLoggable` and `Notifiable` traits to your model. The `Notifiable` is normally setup when you generate a model using the `artisan make:model` command, if it does not be sure to add it.

```
namespace App\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Codebyray\LaravelAuthLog\Traits\AuthenticationLoggable;

class User extends Authenticatable
{
    use Notifiable, AuthenticationLoggable;
}
```

This package will listen to Laravel's Login, Logout, Failed and OtherDeviceLogout events.

Usage
=====

[](#usage)

Getting The Logs
----------------

[](#getting-the-logs)

Get all the authentication logs for a user:

```
$user = User::find(1);
$user->authentications;
// or
User::find(1)->authentications;
// or
auth()->user()->authentications;
```

Get the users last login information:

```
/*
|
| Each method below returns something like for the date & time:
|   Illuminate\Support\Carbon @1664518251 {#1176
|       value: "2022-09-30 06:10:51",
|   }
|
| If requesting th IP the events will return:
|   "127.0.0.1"
|
*/
// Get the date & time of the last login whether it be a failed attempt or successful login.
User::find(1)->lastLoginAt();

// Get the date & time of the last successful login.
User::find(1)->lastSuccessfulLoginAt();

// Get the IP address of the last login whether a failed attempt or successful one.
User::find(1)->lastLoginIp();

// Get the IP address of the last successful login.
User::find(1)->lastSuccessfulLoginIp();
```

Get a users previous successful login time or IP address:

```
// Get the date & time for the users previous successful login.
User::find(1)->previousLoginAt();

// Get the IP address for the users previous successful login.
User::find(1)->previousLoginIp();
```

In the above examples you can use `auth()->user()` to get the logs for the currently logged in user.

Notifications
=============

[](#notifications)

Notifications are sent out via email by default. You can sent them to be sent by 'mail', 'nexmo' and 'slack' by setting them in your 'Authenticatable' model. To setup the channels you want notifications sent, you nee to define the 'notifyAuthenticationLogVia' method in your `Authenticatable` model.

```
public function notifyAuthenticationLogVia()
{
    return ['nexmo', 'mail', 'slack'];
}
```

In order to use '[Slack](https://laravel.com/docs/8.x/notifications#routing-slack-notifications)' and/or '[Nexmo](https://laravel.com/docs/8.x/notifications#routing-sms-notifications)', you need to install the drivers for each and follow their documentation for setting up your 'Authenticatable' models.

New Device Notifications
------------------------

[](#new-device-notifications)

Enabled by default, they use the `\Codebyray\LaravelAuthLog\Notifications\NewDevice` class which can be overridden in the config file.

Failed Login Notifications
--------------------------

[](#failed-login-notifications)

Enabled by default, they use the `\Codebyray\LaravelAuthLog\Notifications\FailedLogin` class which can be overridden in the config file.

Location
--------

[](#location)

If the `torann/geoip package` is installed, you will need to enable locations via the config file. This is disabbled by default.

You can turn this on within the configuration for each template.

Note: By default when working locally, no location will be recorded because it will send back the default address from the geoip config file. You can override this behavior in the email templates.

Purging Old Logs
================

[](#purging-old-logs)

You can purge the logs using the following artisian command:

```
php artisan auth-log:purge
```

Any records older than the specified number of days in the `config/auth-log.php` file via the `purge` setting will be deleted. Default number of days is 365.

```
'purge' => 365,
```

You can schedule the command to run automatically every month, or however often you'd like using the following command:

```
$schedule->command('auth-log:purge')->monthly();
```

Version Compatibility
---------------------

[](#version-compatibility)

LaravelAuth Log9.x1.xTesting
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

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

[](#security-vulnerabilities)

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

Credits
-------

[](#credits)

- [Ray "RJ"](https://github.com/codebyray)
- Original Code - [rappasoft/laravel-authentication-log](https://github.com/rappasoft/laravel-authentication-log)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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

1325d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/56b9f090994212c557bf9e64ab54e367eacc9f614b152be8ff532cc7f3f2565b?d=identicon)[codebyray](/maintainers/codebyray)

---

Top Contributors

[![codebyray](https://avatars.githubusercontent.com/u/2058181?v=4)](https://github.com/codebyray "codebyray (16 commits)")

---

Tags

laravelcodebyraylaravel-auth-log

###  Code Quality

TestsPest

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/codebyray-laravel-auth-log/health.svg)

```
[![Health](https://phpackages.com/badges/codebyray-laravel-auth-log/health.svg)](https://phpackages.com/packages/codebyray-laravel-auth-log)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k89.8M1.0k](/packages/spatie-laravel-permission)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[jeffgreco13/filament-breezy

A custom package for Filament with login flow, profile and teams support.

1.0k1.7M41](/packages/jeffgreco13-filament-breezy)[spatie/laravel-login-link

Quickly login to your local environment

4381.2M1](/packages/spatie-laravel-login-link)[ryangjchandler/laravel-cloudflare-turnstile

A simple package to help integrate Cloudflare Turnstile.

438896.6k2](/packages/ryangjchandler-laravel-cloudflare-turnstile)[spatie/laravel-passkeys

Use passkeys in your Laravel app

444494.4k16](/packages/spatie-laravel-passkeys)

PHPackages © 2026

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