- How do I install and set up Laravel Visitor for my project?
- Run `composer require shetabit/visitor`, publish the migrations with `php artisan vendor:publish`, and execute `php artisan migrate`. Laravel 5.5+ requires no additional provider/alias configuration.
- Can I track visits for specific Eloquent models (e.g., Posts, Products)?
- Yes. Use the `Visitable` trait on your model and call `visitor()->visit($model)` or `$model->createVisitLog()`. Visits are stored in a `visits` relation for querying.
- How does Laravel Visitor detect online users in real-time?
- The package tracks online users via visit logs and provides `isOnline()` and `onlineVisitors()` methods. It’s lightweight but not WebSocket-based—ideal for dashboards or collaborative tools.
- Will this package work with Laravel 10 or older versions?
- Laravel Visitor is actively maintained for Laravel 11–13. Laravel 10 support is deprecated; pin to a stable version or fork if needed. Check the GitHub repo for version-specific branches.
- How do I exclude certain routes (e.g., API or admin) from visit logging?
- Use the `LogVisits` middleware and configure exclusions in its `except` property. For example, add `except: ['admin/*', 'api/*']` to your middleware configuration.
- Does Laravel Visitor support GDPR compliance (e.g., IP anonymization or log purging)?
- The package uses IP-based deduplication, which may conflict with GDPR. Supplement with session tracking for authenticated users and implement `purgeLogs()` for data retention compliance.
- Can I log visits asynchronously to avoid database performance issues?
- Yes. Queue visit logs by modifying the `visit()` method to dispatch a job (e.g., `VisitLogJob`). Use rate limiting (e.g., log every 5th visit for anonymous users) for high-traffic apps.
- How accurate is the device/browser detection (e.g., mobile vs. desktop)?
- The package uses UAParser, which is highly accurate for common user agents. Edge cases (e.g., custom UAs) may require testing or a fallback service like WURFL for precision.
- What’s the difference between `visitor()->visit()` and `$model->createVisitLog()`?
- Both methods log visits, but `visitor()->visit($model)` is a global helper, while `$model->createVisitLog()` is model-specific. The latter is cleaner if you’re already working with a model instance.
- Are there alternatives to Laravel Visitor for tracking user behavior?
- Alternatives include Laravel Analytics (for basic tracking), Spatie’s Analytics (event-based), or third-party services like Google Analytics. Laravel Visitor stands out for its model-agnostic logging and online user detection.