PHPackages                             coderflexx/laravisit - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. coderflexx/laravisit

ActiveLibrary[Database &amp; ORM](/categories/database)

coderflexx/laravisit
====================

A package to keep track of your pages &amp; understand your audience

v2.1.0(11mo ago)43698.7k—6.4%26[3 PRs](https://github.com/coderflexx/laravisit/pulls)1MITPHPPHP ^8.1CI passing

Since Feb 14Pushed 2mo ago5 watchersCompare

[ Source](https://github.com/coderflexx/laravisit)[ Packagist](https://packagist.org/packages/coderflexx/laravisit)[ Docs](https://github.com/coderflexx/laravisit)[ GitHub Sponsors](https://github.com/coderflex)[ RSS](/packages/coderflexx-laravisit/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (13)Versions (23)Used By (1)

 [![Laravisit Logo](docs/images/Logo.png)](docs/images/Logo.png)

[![The Latest Version on Packagist](https://camo.githubusercontent.com/3c84d197f219b258eba57e0f47f06ebf4113a820046bd0cfa8b158149e27fcb5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f646572666c6578782f6c61726176697369742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/coderflexx/laravisit)[![GitHub Tests Action Status](https://camo.githubusercontent.com/e3fff8cc2878d517389a1df561704e0a1548f1ecefc688e846713569bee1d22c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636f646572666c6578782f6c61726176697369742f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473)](https://github.com/coderflexx/laravisit/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/ffa81c818e8b0b8f9f7d1a433bc68a97b4d5f6b3d53f25cbd90b3165f453f7bb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636f646572666c6578782f6c61726176697369742f7068707374616e2e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65)](https://github.com/coderflexx/laravisit/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/5ad09d317cac5abf51455e6a9758a327c68746d60b255e93284d3a9a7d2c5ff6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f646572666c6578782f6c61726176697369742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/coderflexx/laravisit)

A clean way to track your pages &amp; understand your user's behavior

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require coderflexx/laravisit
```

You can publish the config file with:

```
# linux
php artisan vendor:publish --provider="Coderflex\\Laravisit\\LaravisitServiceProvider"

# windows
php artisan vendor:publish --provider="Coderflex\Laravisit\LaravisitServiceProvider"
```

then, run database migration

```
php artisan migrate
```

This is the contents of the published config file:

```
return [
    /*
    |--------------------------------------------------------------------------
    | User Namespace
    |--------------------------------------------------------------------------
    |
    | This value informs Laravisit which namespace you will be
    | selecting to get the user model instance
    | If this value equals to null, "\Coderflex\Laravisit\Models\User" will be used
    | by default.
    |
    */
    'user_namespace' => "\Coderflex\Laravisit\Models\User",
];
```

Usage
-----

[](#usage)

### Use `HasVisits` Trait

[](#use-hasvisits-trait)

The first thing you need to do is, to use `HasVisits` trait, and implement `CanVisit` interface.

```
namespace App\Models\Post;

use Coderflex\Laravisit\Concerns\CanVisit;
use Coderflex\Laravisit\Concerns\HasVisits;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Post extends Model implements CanVisit
{
    ...
    use HasFactory;
    use HasVisits;
    ...
}
```

After this step, you are all set, you can now count visits by using `visit` method

```
$post->visit();
```

You can chain methods to the `visit` method. Here are a list of the available methods:

METHODSYNTAXDESCRIPTIONEXAMPLE`withIp()`string `$ip = null`Set an Ip address (default `request()->ip()`)`$post->visit()->withIp()``withSession()`string `$session = null`Set an Session ID (default `session()->getId()`)`$post->visit()->withSession()``withData()`array `$data`Set custom data`$post->visit()->withData(['region' => 'USA'])``withUser()`Model `$user = null`Set a user model (default `auth()->user()`)`$user->visit()->withUser()`---

By default, you will have unique visits **each day** using `dailyInterval()` method. Meaning, when the users access the page multiple times in a day time frame, you will see just `one record` related to them.

If you want to log users access to a page with different **timeframes**, here are a bunch of useful methods:

METHODSYNTAXDESCRIPTIONEXAMPLE`hourlyInterval()``void`Log visits each hour`$post->visit()->hourlyIntervals()->withIp();``dailyInterval()``void`Log visits each day`$post->visit()->dailyIntervals()->withIp();``weeklyInterval()``void`Log visits each week`$post->visit()->weeklyIntervals()->withIp();``monthlyInterval()``void`Log visits each month`$post->visit()->monthlyIntervals()->withIp();``yearlyInterval()``void`Log visits each year`$post->visit()->yearlyIntervals()->withIp();``customInterval()`mixed `$interval`Log visits within a custom interval`$post->visit()->customInterval( now()->subYear() )->withIp();`### Get The Records With Popular Time Frames

[](#get-the-records-with-popular-time-frames)

After the visits get logged, you can retrieve the data by the following method:

METHODSYNTAXDESCRIPTIONEXAMPLE`withTotalVisitCount()``void`get total visit count`Post::withTotalVisitCount()->first()->visit_count_total``popularAllTime()``void`get popular visits all time`Post::popularAllTime()->get()``popularToday()``void`get popular visits in the current day`Post::popularToday()->get()``popularLastDays()`int `$days`get popular visits last given days`Post::popularLastDays(10)->get()``popularThisWeek()``void`get popular visits this week`Post::popularThisWeek()->get()``popularLastWeek()``void`get popular visits last week`Post::popularLastWeek()->get()``popularThisMonth()``void`get popular visits this month`Post::popularThisMonth()->get()``popularLastMonth()``void`get popular visits last month`Post::popularLastMonth()->get()``popularThisYear()``void`get popular visits this year`Post::popularThisYear()->get()``popularLastYear()``void`get popular visits last year`Post::popularLastYear()->get()``popularBetween()`Carbon `$from`, Carbon `$to`get popular visits between custom two dates`Post::popularBetween(Carbon::createFromDate(2019, 1, 9), Carbon::createFromDat(2022, 1, 3))->get();`Visit Presenter
---------------

[](#visit-presenter)

This package is coming with helpful decorate model properties, and it uses [Laravel Presenter](https://github.com/coderflexx/laravel-presenter) package under the hood.

METHODSYNTAXDESCRIPTIONEXAMPLE`ip()``void`Get the associated IP from the model instance`$post->visits->first()->present()->ip``user()``void`Get the associated User from the model instance`$post->visits->first()->present()->user->name`Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Inspiration
-----------

[](#inspiration)

- [Codecourse Laravel Model Popularity](https://codecourse.com/courses/laravel-model-popularity)

Credits
-------

[](#credits)

- [Oussama Sid](https://github.com/ousid)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance71

Regular maintenance activity

Popularity51

Moderate usage in the ecosystem

Community24

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 64.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~70 days

Recently: every ~132 days

Total

18

Last Release

352d ago

Major Versions

1.x-dev → 2.x-dev2024-03-18

PHP version history (2 changes)v1.0.0PHP ^8.0

2.x-devPHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/fc6700ab1fdaa6344fb382fd2670393b22d15cd2aba3ab4964bc5235abf6e094?d=identicon)[ousid](/maintainers/ousid)

---

Top Contributors

[![ousid](https://avatars.githubusercontent.com/u/21012933?v=4)](https://github.com/ousid "ousid (157 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (43 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (33 commits)")[![juliangarcess](https://avatars.githubusercontent.com/u/41131304?v=4)](https://github.com/juliangarcess "juliangarcess (7 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (2 commits)")[![shtayeb](https://avatars.githubusercontent.com/u/48182832?v=4)](https://github.com/shtayeb "shtayeb (1 commits)")[![marispro](https://avatars.githubusercontent.com/u/5610414?v=4)](https://github.com/marispro "marispro (1 commits)")[![parastooam](https://avatars.githubusercontent.com/u/28684227?v=4)](https://github.com/parastooam "parastooam (1 commits)")

---

Tags

analyticseloquentlaravelphplaravelcoderflexlaravisit

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/coderflexx-laravisit/health.svg)

```
[![Health](https://phpackages.com/badges/coderflexx-laravisit/health.svg)](https://phpackages.com/packages/coderflexx-laravisit)
```

###  Alternatives

[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[spatie/laravel-model-flags

Add flags to Eloquent models

4301.1M1](/packages/spatie-laravel-model-flags)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[spatie/laravel-sql-commenter

Add comments to SQL queries made by Laravel

1931.4M1](/packages/spatie-laravel-sql-commenter)[spatie/laravel-deleted-models

Automatically copy deleted records to a separate table

409109.8k4](/packages/spatie-laravel-deleted-models)[wnx/laravel-backup-restore

A package to restore database backups made with spatie/laravel-backup.

203330.1k2](/packages/wnx-laravel-backup-restore)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
