Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Authentication Log Laravel Package

rappasoft/laravel-authentication-log

View on GitHub
Deep Wiki
Context7

title: Getting Logs weight: 1

Basic Log Retrieval

Get all authentication logs for the user:

User::find(1)->authentications;

Get the latest authentication:

User::find(1)->latestAuthentication;

Login Information Methods

Get the user's last login information:

User::find(1)->lastLoginAt();

User::find(1)->lastSuccessfulLoginAt();

User::find(1)->lastLoginIp();

User::find(1)->lastSuccessfulLoginIp();

Get the user's previous login time & IP address (ignoring the current login):

auth()->user()->previousLoginAt();

auth()->user()->previousLoginIp();

Query Scopes

The AuthenticationLog model provides powerful query scopes for filtering:

use Rappasoft\LaravelAuthenticationLog\Models\AuthenticationLog;

// Filter successful logins
$successfulLogins = AuthenticationLog::successful()->get();

// Filter failed logins
$failedLogins = AuthenticationLog::failed()->get();

// Filter by IP address
$ipLogs = AuthenticationLog::fromIp('192.168.1.1')->get();

// Filter recent logs (last 7 days by default)
$recentLogs = AuthenticationLog::recent(7)->get();

// Filter suspicious activities
$suspicious = AuthenticationLog::suspicious()->get();

// Filter active sessions
$activeSessions = AuthenticationLog::active()->get();

// Filter trusted devices
$trustedDevices = AuthenticationLog::trusted()->get();

// Filter by device ID
$deviceLogs = AuthenticationLog::fromDevice($deviceId)->get();

// Filter for specific user
$userLogs = AuthenticationLog::forUser($user)->get();

// Chain multiple scopes
$recentSuspicious = AuthenticationLog::recent(30)->suspicious()->get();

Statistics

Get comprehensive login statistics:

$user = User::find(1);

// Get all statistics
$stats = $user->getLoginStats();
// Returns:
// [
//     'total_logins' => 150,
//     'failed_attempts' => 5,
//     'unique_devices' => 3,
//     'unique_ips' => 8,
//     'last_30_days' => 45,
//     'last_7_days' => 12,
//     'suspicious_activities' => 2,
//     'trusted_devices' => 2,
// ]

// Or get individual stats
$totalLogins = $user->getTotalLogins();
$failedAttempts = $user->getFailedAttempts();
$uniqueDevices = $user->getUniqueDevicesCount();
$suspiciousCount = $user->getSuspiciousActivitiesCount();
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony