shetabit/visitor
Track and log Laravel visitor info (IP, browser, device, platform, languages, user agent) via request helper, and attach visit logs to models with a Visitable trait. Includes online user detection and visit counting/uniques by IP or user.
Strengths:
Visitable and Visitor traits enable model-specific tracking without bloating core logic.LogVisits middleware automates tracking for routes with bound models, reducing manual instrumentation.Weaknesses:
visit_logs table, which may not suit high-frequency or offline-first use cases.mobiledetectlib (for UA parsing), which is widely used and stable. No major conflicts expected.visit_logs and visitors tables. Assumes MySQL/PostgreSQL; SQLite may need adjustments for online_at timestamps.isOnline()).visit() method under load (e.g., 1K RPS) to validate database write throughput.| Risk Area | Severity | Mitigation |
|---|---|---|
| Database bottlenecks | High | Optimize visit_logs indexes (e.g., ip, model_type, created_at). |
| GeoIP accuracy | Medium | Test with real user agents; consider MaxMind for production. |
| Online user detection | Medium | Validate session store compatibility (e.g., Redis, database). |
| Middleware route exclusions | Low | Document excluded routes in config/visitor.php. |
| PHP 8.4+ compatibility | Low | Already addressed in v4.5.4 (nullable type hints). |
| Migration conflicts | Low | Use --force cautiously; review schema changes in changelog. |
visit_logs writes?$request->visitor() or visitor() helper.LogVisits for automatic tracking.Visitable trait for model-specific logs.Visitor) for global access.visit_logs(ip, model_type, created_at) for queries.onlineVisitors()) can be cached (e.g., Redis) to reduce session checks.visit() writes to a queue (e.g., Laravel Queues).composer require shetabit/visitor.php artisan vendor:publish --provider="Shetabit\Visitor\Provider\VisitorServiceProvider".php artisan migrate.$request->visitor()->browser().visitor()->visit($model).User::online()->get().LogVisits middleware for a subset of routes (e.g., /posts/*).Visitable trait to critical models (e.g., Post, Product).config/visitor.php./login, /password/reset) in middleware.$model->visitLogs()->count()).mobiledetectlib/mobiledetectlib (UA parsing).geoip2/geoip2 (optional, for GeoIP).database, redis, and file session stores.LogVisits middleware to app/Http/Kernel.php.Visitable trait on Eloquent models (e.g., Post).visit() and visitLogs() methods.Visitor trait to User model.onlineVisitors() and isOnline().mobiledetectlib and geoip2 for updates.visit_logs).visitors table backup strategy for compliance.visit() failures (e.g., database errors) for observability.visit_logs growth (e.g., >10% daily increase).LogVisits::except(['/robots.txt'])).config/visitor.php to hash IPs if required.visitor()->debug().visit_logs for malformed entries (e.g., null ip).Visitable to new models.How can I help you explore Laravel packages today?