PHPackages                             iotronlab/laravel-page-view - 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. iotronlab/laravel-page-view

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

iotronlab/laravel-page-view
===========================

Laravel Model Client View Counting Made Easy

v1.1.0(3mo ago)0186MITPHPPHP ^8.2

Since Nov 29Pushed 3mo ago1 watchersCompare

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

READMEChangelog (6)Dependencies (14)Versions (7)Used By (0)

Laravel Page View
=================

[](#laravel-page-view)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8247b81c77a715ae911754b22e4d79f32a60d55b78b44c3ee8b9c0a2fcf54e3b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696f74726f6e6c61622f6c61726176656c2d706167652d766965772e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/iotronlab/laravel-page-view)[![GitHub Tests Action Status](https://camo.githubusercontent.com/22defad70b003f648c1b13965f21e13f0ed5cf6218d98a082707b2f2e27056a4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f696f74726f6e6c61622f6c61726176656c2d706167652d766965772f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473)](https://github.com/iotronlab/laravel-page-view/actions?query=workflow%3Arun-tests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/67ecfd12134fec9b0b8a782e0a93157d28ba6f240522ac2e414700ee9b72ec5b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696f74726f6e6c61622f6c61726176656c2d706167652d766965772e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/iotronlab/laravel-page-view)

A simple package to track page views for any Laravel Eloquent model. It stores view records with IP, session, and user agent information to prevent duplicate counting.

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

[](#installation)

```
composer require iotronlab/laravel-page-view
```

Publish and run the migrations:

```
php artisan vendor:publish --tag="laravel-page-view-migrations"
php artisan migrate
```

Optionally publish the config file:

```
php artisan vendor:publish --tag="laravel-page-view-config"
```

Configuration
-------------

[](#configuration)

```
use Iotronlab\LaravelPageView\LaravelPageView;

return [
    // Auto-prune old page view records
    'range' => [
        'type' => LaravelPageView::MONTH, // or LaravelPageView::YEAR
        'value' => 1
    ],
];
```

Usage
-----

[](#usage)

### 1. Add the trait to your model

[](#1-add-the-trait-to-your-model)

```
use Iotronlab\LaravelPageView\Traits\hasPageView;

class Post extends Model
{
    use hasPageView;
}
```

### 2. Add a `views` column to your model's table

[](#2-add-a-views-column-to-your-models-table)

```
$table->unsignedBigInteger('views')->default(0);
```

### 3. Record page views

[](#3-record-page-views)

```
// In your controller
public function show(Request $request, Post $post)
{
    $post->hasPageViews($request);

    return view('posts.show', compact('post'));
}
```

### 4. Access view data

[](#4-access-view-data)

```
// Get the view count
$post->views;

// Get formatted views (1K, 1.5M, etc.)
$post->formatted_views;

// Get all page view records
$post->pageViews;
```

### Generate fake views for testing

[](#generate-fake-views-for-testing)

```
$post->fakePageViews();        // Creates a view in the past 30 days
$post->fakePageViews(true);    // Creates a view in the next 30 days
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

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

[](#contributing)

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

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

[](#security-vulnerabilities)

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

Credits
-------

[](#credits)

- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance80

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 80% 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 ~230 days

Recently: every ~280 days

Total

6

Last Release

108d ago

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

v1.0.4PHP ^8.2

### Community

Maintainers

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

---

Top Contributors

[![krishzzi](https://avatars.githubusercontent.com/u/36711704?v=4)](https://github.com/krishzzi "krishzzi (16 commits)")[![iotron](https://avatars.githubusercontent.com/u/50877415?v=4)](https://github.com/iotron "iotron (4 commits)")

---

Tags

laraveliotronlablaravel-page-view

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/iotronlab-laravel-page-view/health.svg)

```
[![Health](https://phpackages.com/badges/iotronlab-laravel-page-view/health.svg)](https://phpackages.com/packages/iotronlab-laravel-page-view)
```

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M627](/packages/spatie-laravel-data)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)

PHPackages © 2026

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