PHPackages                             spargon/laravel-auth-logger - 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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. spargon/laravel-auth-logger

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

spargon/laravel-auth-logger
===========================

Laravel Auth Logger stores user authentication logs and sends out notifications whenever a user logs in from a new system.

1.7.0(1y ago)42031[1 issues](https://github.com/Spargon/Laravel-Auth-Logger/issues)MITPHPPHP ^7.4|^8.0

Since Nov 21Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Spargon/Laravel-Auth-Logger)[ Packagist](https://packagist.org/packages/spargon/laravel-auth-logger)[ Docs](https://github.com/spargon/laravel-auth-logger)[ GitHub Sponsors](https://github.com/TechTailor)[ RSS](/packages/spargon-laravel-auth-logger/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (12)Versions (21)Used By (0)

[![](https://camo.githubusercontent.com/2a14f1452d71a153f7709901b86fe7daad1f218d4a81696e45856e3f49b1d5be/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c2d417574682d4c6f676765722e706e673f7468656d653d6c69676874267061636b6167654e616d653d73706172676f6e2532466c61726176656c2d617574682d6c6f67676572267061747465726e3d63697263756974426f617264267374796c653d7374796c655f32266465736372697074696f6e3d4c6f672b616e642b6e6f746966792b75736572732b7768656e657665722b746865792b6163636573732b66726f6d2b6e65772b612b6465766963652e266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d6c6f636b2d636c6f736564)](https://camo.githubusercontent.com/2a14f1452d71a153f7709901b86fe7daad1f218d4a81696e45856e3f49b1d5be/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c2d417574682d4c6f676765722e706e673f7468656d653d6c69676874267061636b6167654e616d653d73706172676f6e2532466c61726176656c2d617574682d6c6f67676572267061747465726e3d63697263756974426f617264267374796c653d7374796c655f32266465736372697074696f6e3d4c6f672b616e642b6e6f746966792b75736572732b7768656e657665722b746865792b6163636573732b66726f6d2b6e65772b612b6465766963652e266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d6c6f636b2d636c6f736564)

[![GitHub release](https://camo.githubusercontent.com/1dc8974fadfb96443b063424cc9ce9c5d2922ecd860d1f51d6275dca4d069cec/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f73706172676f6e2f6c61726176656c2d617574682d6c6f676765722e7376673f7374796c653d666f722d7468652d62616467652626636f6c6f72423d374535374332)](https://packagist.org/packages/spargon/laravel-auth-logger)[![GitHub issues](https://camo.githubusercontent.com/63ca0c294373c8ee7549aad085995e63863bf4da220811454243f86e90247034/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f53706172676f6e2f4c61726176656c2d417574682d4c6f676765722e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/Spargon/Laravel-Auth-Logger/issues)[![Software License](https://camo.githubusercontent.com/c003d4d48be8c870b7f5dfef6e898cc00ece72e12064c1eb199611b0e290ce92/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666f722d7468652d62616467652626636f6c6f72423d463237453430)](license.md)[![Total Downloads](https://camo.githubusercontent.com/7dc097b5f839c246ec01ee0172c9091741dbee5e953e84d18238f35e771ad682/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73706172676f6e2f6c61726176656c2d617574682d6c6f676765722e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/spargon/laravel-auth-logger)[![StyleCI](https://camo.githubusercontent.com/d409bd54664f0f9e932336a949cb313214cba47f28e008de61e8494063ca1ee6/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3331343733303837312f736869656c643f6272616e63683d6d61696e)](https://camo.githubusercontent.com/d409bd54664f0f9e932336a949cb313214cba47f28e008de61e8494063ca1ee6/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3331343733303837312f736869656c643f6272616e63683d6d61696e)

Laravel Auth Logger stores user authentication logs and sends out notifications whenever a user logs in from a new system.

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

[](#installation)

> Laravel Auth Logger requires PHP 7.0+ and currently supports Laravel 7, 8 &amp; 9.

You can install the package via composer:

```
composer require spargon/laravel-auth-logger
```

After installing the **Laravel-Auth-Logger** package, you need run the install command which will take care of everything you need to get started. Type the following artisan command in your console:

```
php artisan auth-logger:install
```

This will publish the `config/auth-logger.php` file, publish the necessary migration files and ask you for permission to run said migrations.

[![Install Command Sample](install-command.jpg)](install-command.jpg)

Once installed, you need to add the **`AuthLogable`** and **`Notifiable`** traits to your authenticatable model (by default its, `App\Models\User` model). These traits provides you with various methods to get the data generated by the auth logger, such as last login time, last login IP address, and sets the channels to notify the user when they login from a new device:

```
use Illuminate\Notifications\Notifiable;
use Spargon\AuthLogger\AuthLogable;
use Illuminate\Foundation\Auth\User as Authenticatable;

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

Usage
-----

[](#usage)

Get all the authentication logs for a user:

```
User::find(1)->auths;
```

Get the user's last login info (includes the current session if the user is logged in):

```
User::find(1)->lastLoginAt(); [or] auth()->user()->lastLoginAt()

User::find(1)->lastLoginIp(); [or] auth()->user()->lastLoginIp()
```

Get the user's previous login time &amp; ip address (ignoring the current login log):

```
User::find(1)->previousLoginAt(); [or] auth()->user()->previousLoginAt()

User::find(1)->previousLoginIp(); [or] auth()->user()->lapreviousLoginIpstLoginAt()
```

### Send New Device Alert Notification

[](#send-new-device-alert-notification)

Notifications may be sent on the `mail`, or/and the `slack` channels. By default AuthLogger will send a notification via the mail driver (provided you have enabled `notify` in `config/auth-logger.php` file).

You can define `notifyAuthLoggerVia` method on the User's Model to determine which channels the notification should be sent to:

```
/**
 * The Auth Logger notifications delivery channels.
 *
 * @return array
 */
public function notifyAuthLoggerVia()
{
    return ['mail', 'slack'];
}
```

### Slack Notifications &amp; Customiziations

[](#slack-notifications--customiziations)

**Note:** If you want to use the `slack` notification channel, you need to install the `laravel/slack-notification-channel` package first otherwise your app will throw a `Driver not supported` error. Be sure to go through the Laravel docs for Slack Pre-requisites [here.](https://laravel.com/docs/8.x/notifications#slack-prerequisites)

You also need to generate a Slack Incoming Webhook from [here](https://slack.com/services/new/incoming-webhook) and then add the generated webhook to your authenticatable model (usually the User) as such:

```
/**
 * Route notifications for the Slack channel.
 *
 * @param  \Illuminate\Notifications\Notification  $notification
 * @return string
 */
public function routeNotificationForSlack($notification)
{
    return 'https://hooks.slack.com/services/T01D8HUCU4.....'; // replace this with the webhook you receive from Slack
}
```

##### Customizing Messages

[](#customizing-messages)

In `config/auth-logger.php` file, you can customize the name of the `Sender`, the `Channel` to receive the notifications on &amp; the `Icon` to show on the notification.

By default all slack messages will be sent to the `#general` channel.

Slack Sample ImageMail Sample Image[![](slack-sample.png)](slack-sample.png)[![](mail-sample.png)](mail-sample.png)### Disabling Notifications

[](#disabling-notifications)

Of course you can disable notifications by setting the `notify` option in your `config/auth-logger.php` configuration file to `false`:

```
'notify' => env('AUTH_LOGGER_NOTIFY', false),
```

### User Agent Parser

[](#user-agent-parser)

This package uses the `jenssegers/agent` package to parse the user's user-agent when sending the alert notification. Take a look at their docs [here](https://github.com/jenssegers/agent) to learn how to use it in your app (ex: in your logs table).

### Delete logs after a while

[](#delete-logs-after-a-while)

You may clear the old authentication log records using the `auth-logger:clear` Artisan command:

```
php artisan auth-logger:clear

```

Records that are older than the number of days specified in the `older` option in your `config/auth-logger.php` will be deleted when you run the above command:

```
'older' => 31,
```

Optional Files
--------------

[](#optional-files)

You can publish the New Device Alert Email view using the command below:

```
php artisan vendor:publish  --tag=auth-logger-views
```

You can also publish the translations file used by the auth-logger using the command below:

```
php artisan vendor:publish  --tag=auth-logger-translations
```

*These are optional files. You don't need to publish them for the package to work. They exist only for cases where you want to make any changes to the files yourself.*

#### Change Database Table Name

[](#change-database-table-name)

If you want to change the name of the auth-logger table, you can do so by changing the vaule of `table_name` in the `config/auth-logger.php` file (this step is optional - you must also update the table name in the migrations/database to reflect the same).

Experimental (dev-geoip)
------------------------

[](#experimental-dev-geoip)

Currently we are experimenting with an implention of Location Tagging (using GeoIP package from Torann). You can checkout the `geoip` branch to play around with it or get the dev-geoip release from packagist using `composer require spargon/laravel-auth-logger:dev-geoip`

*This is an experimental release of location tagging. Accuracy is not 100% guaranteed. Use it at your own risk. PS&gt; This experimental version does not contain the install command.*

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

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

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

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

[](#security-vulnerabilities)

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

Credits
-------

[](#credits)

- [Moinuddin S. Khaja](https://github.com/TechTailor)
- [Yaakov Dahan](https://github.com/yakidahan) ([Original Source Package](https://github.com/yadahan/laravel-authentication-log))
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 97.2% 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

Every ~92 days

Recently: every ~275 days

Total

18

Last Release

489d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/14147474?v=4)[Moinuddin S. Khaja](/maintainers/TechTailor)[@TechTailor](https://github.com/TechTailor)

---

Top Contributors

[![TechTailor](https://avatars.githubusercontent.com/u/14147474?v=4)](https://github.com/TechTailor "TechTailor (35 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (1 commits)")

---

Tags

auth-loggerauthenticationauthentication-logauthentication-loggerhacktoberfestlaravellaravel-authlaravel-packagelogsnew-device-alertnotificationstrack-loginsloglaravelAuthenticationnotificationspargonlaravel-auth-logger

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/spargon-laravel-auth-logger/health.svg)

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

###  Alternatives

[spatie/laravel-health

Monitor the health of a Laravel application

87512.0M164](/packages/spatie-laravel-health)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.6k29.9M145](/packages/laravel-cashier)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k15.1M130](/packages/laravel-pulse)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M130](/packages/roots-acorn)[yadahan/laravel-authentication-log

Laravel Authentication Log provides authentication logger and notification for Laravel.

419677.7k5](/packages/yadahan-laravel-authentication-log)

PHPackages © 2026

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