Download the PHP package maher/laravel-counters without Composer

On this page you can find all versions of the php package maher/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

Counters Management for laravel project.

In some cases, you need to manage the state of the counters in your laravel project, like the number of visitors of your website, or number of view for a post, or number of downloads for a file, this needs to create a new table to save these records, or at least adding new column for your tables to save the count value.
Therefore, with this package, you can create as many counters for your model without needing to create a physical column in your model's table. Moreover, you can store public counters like "number_of_visitors" for your website, without needing to create a whole table to store it.

In summary, this package allows you to manage counters in your laravel project.

Once installed you can do stuff like this:

There are many other methods that are mentioned below.

Installation

Laravel

This package can be used in Laravel 5.4 or higher. If you are using an older version of Laravel You can install the package via composer:

In Laravel 5.5 and higher versions, the service provider will automatically get registered. In older versions of the framework just add the service provider in config/app.php file:

You must publish the migration with:

After the migration has been published you can create the tables by running the migrations:

You can publish the config file with:

Usage

1) Using Counters with no models

First, add the Maher\Counters\Traits\HasCounter trait to your model(s): for example we can add it to Post Model

This package allows the posts to be associated with counters. Every post can associated with multiple counters.

We can create a counter like this, for example, lets create a counter for the number of views for the Post Model.

After that, for example, in the show function of post controller, you can add this line:

By doing this, the counter of number_of_views for every post will be incremented [by the step size] as we show the post.

This package has another functions.

2) Using Counters with no models.

Sometimes, you have general counters that are not associated with any models, for example the number visitor for your website.

Therefore, this package will allow you to deal with Counter with these types.

This Facade has many other functions:

In some cases, you want to increment the counter once for every person, for example no need to increment the number_of_visitors counter every time the same user refreshes the page.

So you can use these functions:

3)Using artisan commands

You can create a Counter from a console with artisan commands. The following command creates the counter number_of_visitors with initial value 0 and step 1

4) Using APIs for counters

In some cases, we are using a single page application, or we don't want to leave the current page. Therefore there are APIs to increment/decrement general/per_model_object counters.

Examples

by Using this link, a json structure of the updated counter will return as response

Moreover, we can increment/decrement objects counters by these methods

And a json structure like the following will return as response

Database Seeding

Here's a sample seede.

Credits

Maher Khdeir
Linked In
Email: [email protected]

Special Thanks

Special Thanks to Spatie , since I learned and followed there structure of building laravel packages.

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-counters with dependencies

PHP Build Version
Package Version
Requires php Version >=7.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 maher/laravel-counters contains the following files

Loading the files please wait ....