- How do I install shetabit/visitor in a Laravel application?
- Run composer require shetabit/visitor; the service provider and Visitor alias are registered by Laravel package discovery, so nothing needs to be added to config/app.php or bootstrap/providers.php. Then publish and run the migrations using php artisan vendor:publish --tag=visitor-migrations followed by php artisan migrate. Optionally publish the config with --tag=visitor-config if you need to change the driver, the table name, or the paths that are excluded from logging.
- Which PHP and Laravel versions does shetabit/visitor support?
- The current README states the package requires PHP 8.4+ and supports Laravel 12+, while release notes claim a wider Laravel 8 to 13 range, so verify composer.json against your exact pins instead of trusting badges or blog posts. Recent releases have largely been community compatibility pull requests for new Laravel and PHP versions, meaning upstream upgrades tend to be absorbed reactively rather than proactively. If you run an older framework version, install into a branch and run your test suite before committing.
- How do I read the visitor's browser, IP, device, and platform in Laravel?
- Call $request->visitor() in a controller or the global visitor() helper anywhere in your app, then chain browser(), platform(), device(), languages(), ip(), useragent(), or request() to get the value you need. The request() method returns the full request input, so avoid persisting or echoing it blindly. All metadata derives from the resolved client IP and user agent, so behind a load balancer or CDN the results are only as accurate as your trusted proxy configuration.
- How do I log visits for an Eloquent model with the Visitable trait?
- Add the Shetabit\Visitor\Traits\Visitable trait to the model you want to track, then call visitor()->visit($model) or $model->createVisitLog() to write a log row linked to that model. You can also call visitor()->visit() with no argument to store a plain visit log. Use visitor()->setVisitor($user)->visit($post) when the log should be attributed to a specific user rather than the current visitor.
- How can I tell if a user is online in Laravel with shetabit/visitor?
- The visitor instance exposes an isOnline method that determines whether the current user, or a user you pass in, is considered online based on stored visit records. It is a simple read against the visits table rather than a presence service, so accuracy depends on how often visits are written for that user. If online-user detection becomes a hot read path, cache or aggregate the result instead of querying the log table on every request.
- How do I stop certain routes or paths from being logged?
- Publish the configuration file with php artisan vendor:publish --tag=visitor-config and use the excluded paths setting so sensitive routes such as login, password reset, and payment callbacks are skipped. Earlier releases had to add route exclusions and password handling, which shows the defaults are not a compliance posture on their own. Revisit your exclusion list whenever you add routes, and never log full request input on endpoints that handle credentials or tokens.
- Is it safe to store visitor IPs and request data with this package?
- The package's purpose is persisting IP addresses, user agents, and optionally the whole request input, so the data-protection decisions are yours rather than the package's. Decide which fields you may legally retain, for how long, and whether IP hashing or truncation should be the default in your app. Full request capture is a PII and secret-leak vector, so exclude auth and payment routes and pair the tables with a retention or purge job plus a data-subject deletion path.
- Does the LogVisits middleware slow down requests?
- Logging is handled by an optional LogVisits middleware that writes a row when a request touches a Visitable-bound model, which means a synchronous INSERT per tracked request with no queue, batching, or aggregation table. On high-traffic routes that write amplification adds up and creates another failure point on the request path. If you need this at volume, plan for a queue-backed writer or your own event listener instead of relying on the middleware as shipped.
- How do I count unique visitors or views per model?
- Each visit is a row in the visits table, so counts come from ordinary Eloquent queries against that table, for example counting rows for a given model. Unique visitor counts usually rely on a distinct IP count, which scans the raw log table and degrades linearly as the table grows. For anything beyond modest volumes, add an aggregate or daily rollup table and keep the raw log only for short-term debugging.
- What are the alternatives to shetabit/visitor for Laravel?
- If you need raw visitor metadata, per-model view counts, or a simple online-user check, this package is a small, framework-idiomatic fit and integration is roughly one to two engineer-days including tests. If the real requirement is product analytics such as funnels, retention, cohorts, or session replay, use a dedicated analytics product instead, because this package is not that. Other options include writing a small custom middleware and table of your own, or choosing a maintained view-counter or analytics package if you want a queue-backed writer and stronger maintenance guarantees.