Download the PHP package sehrgut/eloquent-computed-attributes without Composer

On this page you can find all versions of the php package sehrgut/eloquent-computed-attributes. 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 eloquent-computed-attributes

Eloquent Computed Attributes

Automatically compute attributes on Laravel Eloquent models when their input changes

Computed attributes provide an alternative to Laravel's built-in accessors. In contrast to accessors, computed attributes are not computed when their value is requested, but rather when their dependencies change (computed attributes are persisted in the DB). It should be preferred in cases of resource intensive computations.

It works by listening for a models' saving event and checking whether the dependencies of a computed attribute are dirty. If so, the attribute is recomputed and its new value is updated in the database.

Dependencies of a computed attribute are declared through the signature of the "compute" method. Argument names in that method correspond to attributes on the model. See below for an example on how this works.

Example Use Cases:

Comparison with other options:

Method Use Case Computation time
Laravel Accessors Simple transformations (affected by n+1 issue) On read
laravel-computed-properties Querieable attributes that should be computed on read (avoids n+1 issue). On read
This package Time consuming operations or operations involving external API calls On write

Getting Started

1. Installation

2. Define a computed attribute

Let's say we have a Post model with a text column and a text_excerpt column. Every time the value of text changes, we want to recompute the text_excerpt column. This is what our Post class could look like:

What's happening under the hood:

  1. The HasComputedAttributes trait recognises that by defining computeTextExcerptAttribute, we want to compute a text_excerpt attribute (following the naming convention of Accessors & Mutators)
  2. The trait derives the computed attributes' dependencies from the method signature: If $this->text changes ($text being part of the method signature), text_excerpt needs to be recomputed
  3. On each saving event of the model, if any of the computed attributes' dependencies (arguments of the method) have changed, the method will be called with the updated values as arguments, and its return value will be assigned to $this->text_excerpt before the models' save() method is called.

All versions of eloquent-computed-attributes with dependencies

PHP Build Version
Package Version
Requires illuminate/support Version ^5.4|^5.5|^5.6
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 sehrgut/eloquent-computed-attributes contains the following files

Loading the files please wait ....