Download the PHP package korridor/laravel-computed-attributes without Composer
On this page you can find all versions of the php package korridor/laravel-computed-attributes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download korridor/laravel-computed-attributes
More information about korridor/laravel-computed-attributes
Files in korridor/laravel-computed-attributes
Package laravel-computed-attributes
Short Description Laravel package that adds computed attributes to eloquent models. A computed attribute is an accessor were the computed value is saved in the database.
License MIT
Homepage https://github.com/korridor/laravel-computed-attributes
Informations about the package laravel-computed-attributes
Laravel computed attributes
Laravel package that adds computed attributes to eloquent models. A computed attribute is an accessor where the value is saved in the database. The value can be regenerated or validated at any time. This can increase performance (no calculation at every get/fetch) and it can simplify querying the database (f.e. complex filter system).
[!NOTE] Check out solidtime - The modern Open Source Time-Tracker at solidtime.io
Installation
You can install the package via composer with following command:
If you want to use this package with older Laravel/PHP version please install the 2.2.* version.
You can also publish the config file to change the default configuration (e.g. the model folder path).
Requirements
This package is tested for the following Laravel and PHP versions:
- 12.* (PHP 8.2, 8.3, 8.4)
- 11.* (PHP 8.2, 8.3, 8.4)
- 10.* (PHP 8.1, 8.2, 8.3)
Usage examples
Here is an example of two computed attributes complex_calculation
and sum_of_votes
.
The functions getComplexCalculationComputed
and getSumOfVotesComputed
are calculating the computed attributes.
https://laravel.com/docs/8.x/eloquent#events
For the whole code of this very simple example see the tests/TestEnvironment
folder.
Commands
computed-attributes:generate
This command (re-)calculates the values of the computed attributes and saves the new value.
Query optimization
You can use the computedAttributesGenerate
scope in any model using the ComputedAttributes
trait to extend the query that fetches the models for the calculation.
computed-attributes:validate
This command validates the current values of the computed attributes.
Query optimization
Contributing
I am open for suggestions and contributions. Just create an issue or a pull request.
Local docker environment
The docker
folder contains a local docker environment for development.
The docker workspace has composer and xdebug installed.
Testing
The composer test
command runs all tests with phpunit.
The composer test-coverage
command runs all tests with phpunit and creates a coverage report into the coverage
folder.
Codeformatting/Linting
The composer fix
command formats the code with php-cs-fixer.
The composer lint
command checks the code with phpcs.
License
This package is licensed under the MIT License (MIT). Please see license file for more information.
All versions of laravel-computed-attributes with dependencies
composer/composer Version ^2
illuminate/console Version ^10|^11|^12
illuminate/database Version ^10|^11|^12
illuminate/support Version ^10|^11|^12