PHPackages                             niladam/laravel-visits - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. niladam/laravel-visits

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

niladam/laravel-visits
======================

A simple package to record visits on your eloquent models or pages

2.0.0(2y ago)1117[1 issues](https://github.com/niladam/laravel-visits/issues)MITPHPPHP ^8.1

Since Sep 5Pushed 2y ago1 watchersCompare

[ Source](https://github.com/niladam/laravel-visits)[ Packagist](https://packagist.org/packages/niladam/laravel-visits)[ Docs](https://github.com/niladam/laravel-visits)[ RSS](/packages/niladam-laravel-visits/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (7)Used By (0)

Laravel Visits - simple drop-in package that records visits.
============================================================

[](#laravel-visits---simple-drop-in-package-that-records-visits)

[![Latest Version on Packagist](https://camo.githubusercontent.com/de2e619c4fb2a49897fd1b76af2f4662911666a92abba7686c6f2bcd987d395f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e696c6164616d2f6c61726176656c2d7669736974732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/niladam/laravel-visits)[![Total Downloads](https://camo.githubusercontent.com/c528074938597b7dff437aa74a6419fbf98573cbafbf4350c8086b00597c70de/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e696c6164616d2f6c61726176656c2d7669736974732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/niladam/laravel-visits)

This is a small package that allows you to easily record visits to your models and / or custom URLs, either by using the included middleware or by using the provided helpers.

The package stores the visits in a separate table, so it doesn't bloat your existing tables.

This package makes use of PHP's [inet\_ntop](https://www.php.net/manual/en/function.inet-ntop.php) and [inet\_pton](https://www.php.net/manual/en/function.inet-pton.php) functions to store the IP addresses in a binary format, reducing your database size.

The package tries to keep the visits table simple, with only the following data being stored:

- The IP address of the visitor
- An optional user ID, if the visitor is authenticated
- The platform (`desktop`, `phone`, `tablet`, `robot` or `other`) (makes use of [jenssegers/agent](https://github.com/jenssegers/agent))
- The referer (if any)
- The entity that's being visited
- The URL that's being visited (if not an entity) - by removing the current app URL from the string.

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

[](#installation)

You can install the package via composer:

```
composer require niladam/laravel-visits
```

Publish the migration with:

```
php artisan vendor:publish --provider="Niladam\LaravelVisits\LaravelVisitsServiceProvider" --tag="migrations"
```

Publish the config file with:

```
php artisan vendor:publish --provider="Niladam\LaravelVisits\LaravelVisitsServiceProvider" --tag="config"
```

Run the migrations:

```
php artisan migrate --step
```

Prepare your model, implementing the `CanHaveVisits` interface and the `HasVisits` trait.
-----------------------------------------------------------------------------------------

[](#prepare-your-model-implementing-the-canhavevisits-interface-and-the-hasvisits-trait)

Here's an example:

```
