Package: areia-lab/laravel-login-notifier
A Laravel package to monitor user logins, detect new devices or IP addresses, log device and location information, and notify users and admins of suspicious or new login activity.
- Detect logins from new devices or IP addresses.
- Send email notifications to users on new logins.
- Send alerts to admin for every login.
- Log device, browser, platform, IP, and geo-location.
- Fully configurable via a config file.
- Supports queueable notifications for production.
This package requires the following:
- PHP
^8.1 - Laravel
^10.0 - jenssegers/agent
^2.6– device & browser detection - stevebauman/location
^7.0– IP geolocation lookup
composer require areia-lab/laravel-login-notifierPublish the configuration and migration files:
php artisan vendor:publish --tag=login-notifier-config
php artisan vendor:publish --tag=login-notifier-migrations
php artisan migrateThe migrations will create the
login_historiestable to store login data.
Edit the published config file config/login-notifier.php:
return [
'notify_user' => env('LOGIN_NOTIFIER_NOTIFY_USER', true),
// Email address to receive admin notifications
'notify_admin' => env('LOGIN_NOTIFIER_NOTIFY_ADMIN', true),
'admin_email' => env('LOGIN_NOTIFIER_ADMIN_EMAIL', 'admin@example.com'),
'secure_url' => env('LOGIN_NOTIFIER_SECURE_URL', 'forgot-password'),
];This package works automatically on every login. You don’t need to call anything manually.
use Illuminate\Support\Facades\Auth;
Auth::attempt(['email' => 'user@example.com', 'password' => 'password']);The following happens automatically:
- Login is recorded in
login_histories. - New device/IP detection is performed.
- User notification is sent if enabled.
- Admin notification is sent if enabled.
The package provides a facade for querying login histories:
use AreiaLab\LoginNotifier\Facades\LoginHistory;
// Get all login histories
$all = LoginHistory::getAllHistories();
// Get recent 10 logins
$recent = LoginHistory::getRecentHistories(10);
// Get all logins for a specific user
$userLogins = LoginHistory::getUserHistories($userId);
// Get last login of a user
$lastLogin = LoginHistory::getLastLoginForUser($userId);
// Get logins from new devices for a user
$newDeviceLogins = LoginHistory::getNewDeviceLoginsForUser($userId);- Sent to users on login from a new device or IP.
- Includes: IP, device, browser, platform, location, timestamp.
- Includes a call-to-action button to secure the account.
- Sent to admin on every login.
- Includes user login details: IP, device, browser, location, timestamp.
- Provides a link to review user activity in the admin dashboard.
Contributions, issues, and feature requests are welcome!
- Fork the repo.
- Create a feature branch.
- Submit a Pull Request.
MIT License. See LICENSE for details.