- How do I install and configure coderflexx/laravisit in a Laravel application?
- Install it with composer require coderflexx/laravisit, then publish and run the package migration and publish its config file. Add the HasVisits trait to any Eloquent model you want to track and record a visit through the trait's visit method, optionally attaching the request IP or user agent. Budget around half a day for a first vertical slice, most of it spent on schema and backfill decisions rather than the package itself.
- Which Laravel and PHP versions does laravisit support?
- Version 2.2.0 is a compatibility release that adds Laravel 13.x and PHP 8.4 support, with CI coverage across Laravel 10, 11, 12, and 13 and PHP 8.1 through 8.4. If you are on Laravel 10 to 12 with PHP 8.1 to 8.3, the earlier 2.1.x line covers you as well. Confirm whether your target Laravel 13 install is a stable release before pinning v2.2.0 in production.
- Does laravisit track visits with middleware or a model trait?
- Laravisit attaches at the model layer through a polymorphic HasVisits trait rather than an HTTP middleware. That means no route coupling, no middleware ordering concerns, and no response-lifecycle involvement, but you decide explicitly which models and which actions record a visit. Tracking is fully removable by dropping the trait and the visits table.
- How do I get the most popular pages or models with laravisit?
- Visits are stored in a Visit model tied polymorphically to your tracked Eloquent model, so you can query Visit directly or through the relationship on the model. Order by a count aggregate to build a popular-this-week list, and scope results with timestamp where clauses for date ranges. Because it is plain Eloquent, you can group, join, and cache the results using your normal reporting patterns.
- Does laravisit count unique visitors or filter out bots?
- Laravisit records raw visits such as IP address, user agent, referrer, and timestamps, and leaves deduplication and bot exclusion up to you. If you need unique-visitor counts, plan a distinct query over IP and user agent with a supporting index, or maintain a rollup table. Bot filtering can be applied by inspecting the stored user agent at write time or when building reports.
- Is laravisit a good alternative to Google Analytics for a Laravel app?
- It is a lightweight, self-hosted option for developers who want view counts inside their own database instead of a third-party script. You get page views, referrers, browsers, devices, and countries, but not the session, funnel, or campaign tooling a hosted platform offers. For popularity metrics on content models it is usually sufficient and keeps visitor data on your own infrastructure.
- How does caching in laravisit affect visit counts?
- Visit counting is typically aggregated through the package's caching path, so a wrong TTL or an unexpected cache-store behavior can produce silently incorrect numbers. Watch for assumptions about cache tagging and for caches shared across web, queue, and console contexts. Validate aggregated counts against raw rows after deployment, since these errors surface in product metrics rather than as exceptions.
- What is the risk of the coderflexx/laravel-presenter dependency?
- Laravisit requires coderflexx/laravel-presenter ^2.2, a second small package from the same maintainer, bumped specifically for Laravel 13 compatibility. That is a transitive dependency you cannot easily fork around, and both packages would need to be abandoned or go unmaintained together. The version bump itself carries low breaking-change risk; maintainer concentration is the material concern.
- How should I handle visits table growth and retention?
- Every tracked view is an insert, so the visits table grows monotonically and should be treated as a schema and retention decision rather than a package feature. Common approaches are keeping raw events for a fixed window, rolling up into nightly aggregate counts, or partitioning by date. Decide this before launch so your indexes and rollup jobs match the reporting queries you actually run.
- Can I customize the laravisit migration for multi-tenant or custom schemas?
- Yes, the migration and config are published into your application, so you can add a tenant column, composite indexes, or extra visit attributes. In a strictly isolated multi-tenant database you will want the tenant key on the visits table and every query scoped to it. Because the package is a narrow model-layer capability, these changes stay local and do not constrain your application structure.