PHPackages                             jangaraev/laravel-impressionable - 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. jangaraev/laravel-impressionable

ActiveLibrary

jangaraev/laravel-impressionable
================================

Views count for Eloquent models for Laravel

06PHP

Since May 23Pushed 3y ago1 watchersCompare

[ Source](https://github.com/jangaraev/laravel-impressionable)[ Packagist](https://packagist.org/packages/jangaraev/laravel-impressionable)[ RSS](/packages/jangaraev-laravel-impressionable/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependenciesVersions (2)Used By (0)

laravel-impressionable
======================

[](#laravel-impressionable)

[![Total Downloads](https://camo.githubusercontent.com/bc95c5ec7a4f164b1e0de118b3626bbb2feff509e7647b82f7e947a7f79826f1/687474703a2f2f706f7365722e707567782e6f72672f6a616e6761726165762f6c61726176656c2d696d7072657373696f6e61626c652f646f776e6c6f616473)](https://packagist.org/packages/jangaraev/laravel-impressionable)[![License](https://camo.githubusercontent.com/9195cab4dd84b96c89ddff63278845c152cced5daea96aec896a53c3cc4f153b/687474703a2f2f706f7365722e707567782e6f72672f6a616e6761726165762f6c61726176656c2d696d7072657373696f6e61626c652f6c6963656e7365)](https://packagist.org/packages/jangaraev/laravel-impressionable)

A useful package to automate impressions (views) counting.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
- [Morph map](#morph-map)
- [License](#license)

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

[](#installation)

```
$ composer require jangaraev/laravel-impressionable
```

You also have to publish the migration file which creates a DB table to store impressions data. Run the newly published migration.

```
$ php artisan vendor:publish --provider="Jangaraev\LaravelImpressionable\ImpressionableServiceProvider" --tag="migrations"
$ php artisan migrate
```

Usage
-----

[](#usage)

Align appropriate models by declaring the interface and add the helper trait.

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Jangaraev\LaravelImpressionable\Contracts\Impressionable;
use Jangaraev\LaravelImpressionable\Traits\CountsImpressions;

class MyModel extends Model implements Impressionable
{
    use CountsImpressions;
}
```

Once done, it's now possible to call the `incrementImpressions()` method on that model.

Typically in the `show()` method of a controller:

```
public function show(string $slug)
{
    $modelInstance = $modelRepository::getBySlug($slug);

    // fetching related models, doing required checks, setting up meta tags, etc

    $modelInstance->incrementImpressions();

    return view('show', compact('modelInstance'));
}
```

Printing impressions is as easy as

```
// prints value from DB
echo $model->impressions;
```

Morph Map
---------

[](#morph-map)

It's possible to add a *morph map* to introduce a shorter and more user-friendly model names that will be written to DB instead of the model's fully-qualified name.

```
+------------+---------------------+-------------------+------------+
| date       | impressionable_type | impressionable_id | ip         |
+------------+---------------------+-------------------+------------+
| 2022-05-17 | foo                 |                65 | 2130706433 |
| 2022-05-17 | \App\Models\Foo     |                65 | 2130706433 |
+------------+---------------------+-------------------+------------+

```

The first row is written using morph map and the second one is not, both references the same model.

*Important!* You can't combine both approaches. If you have morph relationships already written and referenced in the DB, they become invalid when you introduce them to the morph map.

*Say, you have a model `Cat` which is already referenced in the DB. If you re-map it in morph map to anything different from model's FQN then you'll get your references dead. A solution here is to map models from the very beginning or create a migration which will re-map existing references to the new writing.*

Example of a typical morph map which is registered via service provider:

```
namespace App\Providers;

use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\ServiceProvider;

class MorphMapServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Relation::morphMap([
            'cat' => \App\Models\Cat::class,
            'dog' => \App\Models\Dog::class,
            // ...
            'foo' => \App\Models\Foo::class,
            'bar' => \App\Models\Bar::class,
        ]);
    }
}
```

License
-------

[](#license)

Package is an open-sourced laravel package licensed under the MIT license.

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity28

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/5156b25a4e9f1af8e56beccc120425bc12c36e8ef5ec77d0032022b565aed256?d=identicon)[jangaraev](/maintainers/jangaraev)

---

Top Contributors

[![jangaraev](https://avatars.githubusercontent.com/u/101257372?v=4)](https://github.com/jangaraev "jangaraev (9 commits)")

### Embed Badge

![Health badge](/badges/jangaraev-laravel-impressionable/health.svg)

```
[![Health](https://phpackages.com/badges/jangaraev-laravel-impressionable/health.svg)](https://phpackages.com/packages/jangaraev-laravel-impressionable)
```

PHPackages © 2026

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