Download the PHP package spatie/laravel-stats without Composer

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

Track application stat changes over time

Latest Version on Packagist Tests Total Downloads

This package is a lightweight solution to summarize changes in your database over time. Here's a quick example where we are going to track the number of subscriptions and cancellations over time.

First, you should create a stats class.

Next, you can call increase on it when somebody subscribes, and decrease when somebody cancels their plan.

With this in place, you can query the stats. Here's how you can get the subscription stats for the past two months, grouped by week.

This will return an array like this one:

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

You must publish and run the migrations with:

Usage

Step 1: create a stats class

First, you should create a stats class. This class is responsible for configuration how a particular statistic is stored. By default, it needs no configuration at all.

By default, the name of the class will be used to store the statistics in the database. To customize the used key, use getName

Step 2: call increase and decrease or set a fixed value

Next, you can call increase, decrease when the stat should change. In this particular case, you should call increase on it when somebody subscribes, and decrease when somebody cancels their plan.

Instead of manually increasing and decreasing the stat, you can directly set it. This is useful when your particular stat does not get calculated by your own app, but lives elsewhere. Using the subscription example, let's image that subscriptions live elsewhere, and that there's an API call to get the count.

By default, that increase, decrease and set methods assume that the event that caused your stats to change, happened right now. Optionally, you can pass a date time as a second parameter to these methods. Your stat change will be recorded as if it happened on that moment.

Step 3: query the stats

With this in place, you can query the stats. You can fetch stats for a certain period and group them by minute, hour, day, week, month, or year.

Here's how you can get the subscription stats for the past two months, grouped by week.

This will return an array containing arrayable Spatie\Stats\DataPoint objects. These objects can be cast to arrays like this:

Extended Use-Cases

Read and Write from a custom Model

Read and Write from a HasMany-Relationship

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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


All versions of laravel-stats with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/contracts Version ^8.73|^9.0|^10.0|^11.0
spatie/laravel-package-tools Version ^1.9.2
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 spatie/laravel-stats contains the following files

Loading the files please wait ....