Download the PHP package turahe/laravel-counters without Composer

On this page you can find all versions of the php package turahe/laravel-counters. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-counters

Laravel Counters

PHP Tests Codecov Latest Release Latest Version PHP Version

A modern, optimized counter management package for Laravel 11/12/13 with PHP 8.4 and 8.5 support.

A flexible and powerful counter management system for Laravel applications. Easily track and manage various types of counters like page views, downloads, user actions, and more without cluttering your database schema.

🚀 Features

📋 Table of Contents

Installation

Requirements

Step-by-Step Installation

  1. Install the package via Composer:

  2. Publish the configuration and migrations:

This will publish:

  1. Run the migrations:

This creates the counters and counterables tables in your database.

Quick Start

1. Create a Counter

2. Use with Models

3. Track Views

4. Global Counters

Usage

Model Counters

Add the HasCounter trait to any model you want to track:

Available Methods

Global Counters

Use the Counters facade for system-wide counters:

Cookie-based Tracking

Prevent duplicate increments from the same user:

API Reference

Model Methods (HasCounter Trait)

Method Description Parameters
addCounter($key, $initialValue = null) Add counter to model $key: Counter key, $initialValue: Optional initial value
getCounter($key) Get counter object $key: Counter key
getCounterValue($key) Get counter value $key: Counter key
hasCounter($key) Check if model has counter $key: Counter key
incrementCounter($key, $step = null) Increment counter $key: Counter key, $step: Optional step value
decrementCounter($key, $step = null) Decrement counter $key: Counter key, $step: Optional step value
resetCounter($key, $initialValue = null) Reset counter $key: Counter key, $initialValue: Optional reset value
removeCounter($key) Remove counter from model $key: Counter key

Global Counter Methods (Counters Facade)

Method Description Parameters
create($key, $name, $initialValue = 0, $step = 1) Create a counter $key: Counter key, $name: Display name, $initialValue: Initial value, $step: Step value
get($key) Get counter object $key: Counter key
getValue($key, $default = null) Get counter value $key: Counter key, $default: Default value if not found
setValue($key, $value) Set counter value $key: Counter key, $value: New value
setStep($key, $step) Set counter step $key: Counter key, $step: Step value
increment($key, $step = null) Increment counter $key: Counter key, $step: Optional step value
decrement($key, $step = null) Decrement counter $key: Counter key, $step: Optional step value
reset($key) Reset counter $key: Counter key
incrementIfNotHasCookies($key) Increment if no cookie $key: Counter key
decrementIfNotHasCookies($key) Decrement if no cookie $key: Counter key

Configuration

The package configuration is located at config/counter.php:

Customizing Table Names

You can customize the table names in the configuration:

Artisan Commands

Create Counter

Create a counter via command line:

Parameters:

Testing

The package includes a comprehensive test suite covering model counters, global counters, cookie-based tracking, exceptions, and configuration.

Local

Generate an HTML coverage report locally:

Docker

Run tests in a container (default: PHP 8.5 + Laravel 13):

Makefile

Run the full CI matrix (PHP 8.4/8.5 × Laravel 11/12/13):

Coverage

Coverage is uploaded to Codecov on every push and pull request via the Codecov workflow.

What's tested

Common Usage Patterns

✅ Best Practices

  1. Always create counters before using them:

  2. Use meaningful counter keys:

  3. Handle counter existence gracefully:

❌ Common Mistakes

  1. Don't forget to run migrations:

  2. Don't use counters without creating them first:

Performance Optimizations

Caching

The package includes built-in caching for counter lookups, significantly improving performance for frequently accessed counters.

Bulk Operations

Use bulk operations to update multiple counters efficiently:

Database Indexes

The migration includes optimized indexes for better query performance.

PHP 8.4+ Features Used

Laravel 11/12/13 Features Used

Example Seeder

Example seeder for creating counters:

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This package is open-sourced software licensed under the MIT license.

Support


Made with ❤️ by Nur Wachid


All versions of laravel-counters with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
illuminate/support Version ^11.0 || ^12.0 || ^13.0
illuminate/database Version ^11.0 || ^12.0 || ^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package turahe/laravel-counters contains the following files

Loading the files please wait ...