Download the PHP package romanzipp/laravel-projectable-aggregates without Composer

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

Laravel Projectable Aggregates

Latest Stable Version Total Downloads License GitHub Build Status

What

Laravel Projectable Aggregates is a package that allows you to easily store aggregate values like counts, sums, averages, etc. in your models eliminating the need to calculate these values on the fly (with withCount, withSum, withAvg, etc.).

Installation

Terminology

🟢 Consumers

Consumers hold the projectable aggregate database field. This is the model which otherwise would calculate the relationship fields via withCount, withSum, withAvg, etc.

🔵 Providers

Providing models provide (duh) the aggregate values for the consumer. Think of the provider to exist many times for one consumer.

Usage

Let's continue with the example of a Car model with Door models. We want to store the Doors count in the Car's project_doors_count field.

1. Add a Projection Field to DB

2. Update your Models

🟢 Car (Consumer)

The consumer model will attach the ConsumesProjectableAggregate attribute to the provider relation.

🔵 Door (Provider)

The provider model will attach the ProvidesProjectableAggregate attribute to the consumer relation.

3. Register the Projection Aggregates

In order to listen to model events issued by the provider models, you need to register the consumer models in the boot method of your AppServiceProvider.

Documentation

[!IMPORTANT]
Calculating aggregate values (without bulk) relies on Elouent model events which are only dispatched when working with Eloquent model itself. Using the DB facade will not trigger the library to update the aggregate values.

Aggregate Types

There are three types of aggregates that can be calculated:

[!IMPORTANT]
In order to use the aggregate types TYPE_SUM and TYPE_AVG, you need to specify the target attribute of the relationship.

Triggers

You can decide if you would only like to rely on models events or if you want to calculate the aggregate values periodically in bulk.

Rely on Model Events

This will automatically work if your've attached the ProvidesProjectableAggregate attribute to your provider relations. Once a provider model has been created/deleted the according consumer aggregate attribute will be incremented/decremented.

Calculate periodically in Bulk

If you don't want to or can't rely on model events, you can use the bulk-aggregate command to calculate the aggregate values periodically in bulk.

Relationships

The following relationships are supported and tested:

Consumer::hasMany()

Consumer::hasManyThrough() ⚠️ WIP

Consumer::morphMany()

Testing

This repository contains a Lando configuration file that can be used to run the tests on your local machine.

License

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


All versions of laravel-projectable-aggregates with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/support Version ^10.0|^11.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 romanzipp/laravel-projectable-aggregates contains the following files

Loading the files please wait ....