Download the PHP package syriable/laravel-user-context without Composer
On this page you can find all versions of the php package syriable/laravel-user-context. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download syriable/laravel-user-context
More information about syriable/laravel-user-context
Files in syriable/laravel-user-context
Package laravel-user-context
Short Description User presence, timezone awareness, locale context and login metadata for Laravel — know who is online, where they are, and what time it is for them.
License MIT
Homepage https://github.com/syriable/laravel-user-context
Informations about the package laravel-user-context
Laravel User Context
Know who is online, where they are, and what time it is for them — presence, timezone awareness, locale context and login metadata for any Laravel app.
A lightweight, database-driven foundation package. No Redis, no heavy dependencies — presence works without a queue worker; geolocation lookups are queued by default so they never block the request path.
Requirements
- PHP 8.3+
- Laravel 11, 12 or 13
Installation
Publish and run the migrations:
Optionally publish the config file:
Add the trait to your authenticatable model:
Register the tracking middleware so activity is recorded on each request. In
bootstrap/app.php (Laravel 11+):
That's it — logins, logouts, presence, locale and (optionally) geolocation are now tracked automatically.
Documentation
Publish the config (php artisan vendor:publish --tag="laravel-user-context-config")
and read the comments in config/user-context.php for every key. Notable defaults:
| Key | Default | Why |
|---|---|---|
ip.privacy |
anonymize |
Store /24 (IPv4) / /48 (IPv6) — not raw IPs |
geolocation.driver |
null |
No external lookup until you opt into ipinfo / maxmind / ipapi |
queue.enabled |
true |
Geo lookups never block the request that recorded activity |
routes.middleware |
web, auth, throttle:60,1 |
Heartbeat is auth-gated and rate-limited |
Usage at a glance
Presence
Keep a browser tab "online" with the bundled heartbeat component:
Presence source
Laravel's database session driver already records last_activity,
ip_address and user_agent for the authenticated user on every request.
Rather than duplicate that, the package can read presence straight from
Laravel's own sessions table. This is controlled by presence.source:
| Value | Behavior |
|---|---|
auto (default) |
Read from sessions when the database session driver is active and the table exists; otherwise fall back to the package's own columns. |
sessions |
Always read from Laravel's sessions table (requires the database session driver). |
table |
Always read from the package's user_contexts columns — works on every session driver, supports polymorphic user models, and keeps the package's IP privacy modes. |
auto targets applications with a single authenticatable type. Presence
reads (isOnline(), presence()->lastSeen(), location()->ipAddress(),
location()->userAgent()) flow through the active source; login/logout
timestamps, timezone, locale and geolocation always come from the package's
own table, since Laravel's sessions table does not record them. The
package still writes its own columns regardless of this setting, so
switching sources never loses data.
[!NOTE] In
sessionsmodelocation()->ipAddress()returns the raw address Laravel stores on the session row; theuser-context.ip.privacymodes (anonymize / hash / discard) apply only intablemode. Multi-guard or polymorphic setups should use thetablesource, because Laravel'ssessions.user_idhas no morph type.
Timezone & locale
Location
User-to-user time comparison
Blade components
API
GET /user-context/me returns the authenticated user's context:
Events
Listen for any of: UserOnline, UserOffline, UserLocationUpdated,
UserTimezoneChanged, UserLoginRecorded. See Extending.
Testing
Changelog
Please see CHANGELOG for what has changed recently.
Credits
- syriable
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-user-context with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^11.0||^12.0||^13.0