PHPackages                             nodes/counter-cache - 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. nodes/counter-cache

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

nodes/counter-cache
===================

Counter caching for Laravel

2.0.5(6y ago)1213.9k4[4 issues](https://github.com/nodes-php/nodes-php-counter-cache/issues)1MITPHP

Since Dec 6Pushed 6y ago3 watchersCompare

[ Source](https://github.com/nodes-php/nodes-php-counter-cache)[ Packagist](https://packagist.org/packages/nodes/counter-cache)[ Docs](http://nodesagency.com)[ RSS](/packages/nodes-counter-cache/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (2)Versions (18)Used By (1)

Counter Cache
-------------

[](#counter-cache)

⚠️**This package is deprecated**⚠️

Brings the ruby concept of "counter caching" to [Laravel](http://laravel.com/docs).

[![Total downloads](https://camo.githubusercontent.com/5e9028fe4a17a386ef7143686f366a079d2b2413572bc5f334863f1920402429/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e6f6465732f636f756e7465722d63616368652e737667)](https://packagist.org/packages/nodes/counter-cache)[![Monthly downloads](https://camo.githubusercontent.com/2f3444b089fd254984e371096b2c0bebde930ff3883047651541eb5d4b673a9b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6e6f6465732f636f756e7465722d63616368652e737667)](https://packagist.org/packages/nodes/counter-cache)[![Latest release](https://camo.githubusercontent.com/999d176af3d752f72a1012bee6b7898272bb870738940435a56d20f5705c5bb1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6f6465732f636f756e7465722d63616368652e737667)](https://packagist.org/packages/nodes/counter-cache)[![Open issues](https://camo.githubusercontent.com/064676615780bc35b46e7ee2b6459be964cb1f4f0e685bfb189651a3c1e0a5fb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6e6f6465732d7068702f636f756e7465722d63616368652e737667)](https://github.com/nodes-php/counter-cache/issues)[![License](https://camo.githubusercontent.com/14e4889fde1cfe263188c438353f6b0367e38919015f7bb7b8b5835cc512bdde/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6e6f6465732f636f756e7465722d63616368652e737667)](https://packagist.org/packages/nodes/counter-cache)[![Star repository on GitHub](https://camo.githubusercontent.com/1284854cb0f0dca70b07701dcb4c652d053bd29eb9b57bbbfccce99a635e6c43/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6e6f6465732d7068702f636f756e7465722d63616368652e7376673f7374796c653d736f6369616c266c6162656c3d53746172)](https://github.com/nodes-php/counter-cache/stargazers)[![Watch repository on GitHub](https://camo.githubusercontent.com/83b9f3a976509f0c12cc0f6accc04672e72222b409c66cd4f734e7fc7c963ab7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f77617463686572732f6e6f6465732d7068702f636f756e7465722d63616368652e7376673f7374796c653d736f6369616c266c6162656c3d5761746368)](https://github.com/nodes-php/counter-cache/watchers)[![Fork repository on GitHub](https://camo.githubusercontent.com/a728589376dcc03540f17484b3f4ea95c2db9065f4028b7844e09d217fae6788/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f6e6f6465732d7068702f636f756e7465722d63616368652e7376673f7374796c653d736f6369616c266c6162656c3d466f726b)](https://github.com/nodes-php/counter-cache/network)[![StyleCI](https://camo.githubusercontent.com/9504905c660d08ebcd8bcdb9c5e82ae6da45fbd57afddabda9e4ea8530562d65/68747470733a2f2f7374796c6563692e696f2f7265706f732f34373530303430382f736869656c64)](https://styleci.io/repos/47500408)

📝 Introduction
--------------

[](#-introduction)

One thing we at [Nodes](http://nodesagency.com) have been missing in [Laravel](http://laravel.com/docs) is the concept of "counter caching".

Laravel comes "out of the box" with the [increment](http://laravel.com/docs/5.1/queries#updates)/[decrement](http://laravel.com/docs/5.1/queries#updates) methods on it's [Eloquent](http://laravel.com/docs/5.1/eloquent) models. But you'll need to manually execute these methods everytime, you've saved/delete stuff with your model.

Since the [increment](http://laravel.com/docs/5.1/queries#updates)/[decrement](http://laravel.com/docs/5.1/queries#updates) methods always +1/-1, you can't 100% rely on these as cached value. What if you forgot to execute the decrement method when you deleted a row. Or what if someone deleted a row directly from the database, then your count would be "out of sync".

Therefore we've created this package which brings "counter caching" to [Laravel](http://laravel.com/docs).

The difference between this package and Laravel's [increment](http://laravel.com/docs/5.1/queries#updates)/[decrement](http://laravel.com/docs/5.1/queries#updates) is that our package actually generates and fires a SQL count statement, that counts the entries and updates the desired column with the result.

This way you're always 100% sure that the value in your "counter cache" column is correct.

📦 Installation
--------------

[](#-installation)

To install this package you will need:

- Laravel 5.1+
- PHP 5.5.9+

You must then modify your `composer.json` file and run `composer update` to include the latest version of the package in your project.

```
"require": {
    "nodes/counter-cache": "^1.0"
}
```

Or you can run the composer require command from your terminal.

```
composer require nodes/counter-cache:^1.0
```

⚙ Usage
-------

[](#-usage)

Please refer to the [Wiki documentation](https://github.com/nodes-php/counter-cache/wiki) for more information.

🏆 Credits
---------

[](#-credits)

This package is developed and maintained by the PHP team at [Nodes Agency](http://nodesagency.com)

[![Follow Nodes PHP on Twitter](https://camo.githubusercontent.com/a898a5b14227bafa0c17c43be4f67460fe2b1dc3b88627d7b959e7fae4256a45/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f666f6c6c6f772f6e6f6465737068702e7376673f7374796c653d736f6369616c)](https://twitter.com/nodesphp) [![Tweet Nodes PHP](https://camo.githubusercontent.com/8c1a307180498b3bb360cf73e63da1bfa3afc0306f601be021acd1e85d2bb4e4/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f75726c2f687474702f6e6f6465737068702e7376673f7374796c653d736f6369616c)](https://twitter.com/nodesphp)

📄 License
---------

[](#-license)

This package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~118 days

Recently: every ~225 days

Total

14

Last Release

2281d ago

Major Versions

0.1.3 → 1.0.02016-05-30

1.0.3 → 2.0.02017-02-16

### Community

Maintainers

![](https://www.gravatar.com/avatar/3aaee2c2b7632254faa8a589817712bdab2c7d46778fb26994eef75b20ec9c08?d=identicon)[nodes](/maintainers/nodes)

---

Top Contributors

[![Casperhr](https://avatars.githubusercontent.com/u/1279756?v=4)](https://github.com/Casperhr "Casperhr (12 commits)")[![carmenioanamihaila](https://avatars.githubusercontent.com/u/20821982?v=4)](https://github.com/carmenioanamihaila "carmenioanamihaila (9 commits)")[![rugaard](https://avatars.githubusercontent.com/u/179868?v=4)](https://github.com/rugaard "rugaard (3 commits)")[![fadugyamfi](https://avatars.githubusercontent.com/u/647321?v=4)](https://github.com/fadugyamfi "fadugyamfi (1 commits)")[![mdemblani](https://avatars.githubusercontent.com/u/6511689?v=4)](https://github.com/mdemblani "mdemblani (1 commits)")[![Zeneo](https://avatars.githubusercontent.com/u/5598307?v=4)](https://github.com/Zeneo "Zeneo (1 commits)")

---

Tags

laraveldatabasemodelnodescounter cache

### Embed Badge

![Health badge](/badges/nodes-counter-cache/health.svg)

```
[![Health](https://phpackages.com/badges/nodes-counter-cache/health.svg)](https://phpackages.com/packages/nodes-counter-cache)
```

###  Alternatives

[waad/laravel-model-metadata

A robust Laravel package for handling metadata with JSON casting, custom relation names, and advanced querying capabilities.

823.1k](/packages/waad-laravel-model-metadata)[designmynight/laravel-elasticsearch

Use Elasticsearch as a database in Laravel to retrieve Eloquent models and perform aggregations.

3038.6k](/packages/designmynight-laravel-elasticsearch)[nevadskiy/laravel-translatable

Add translations to your Eloquent models

2120.4k1](/packages/nevadskiy-laravel-translatable)[jrsaunders/shard-matrix

A Complete Database Sharding system for MYSQL and/or Postgres. Using Laravels Query Builder easily scale up your application. Configure your whole solution in one Yaml Config file.

271.5k](/packages/jrsaunders-shard-matrix)

PHPackages © 2026

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