{"repo":"korridor/laravel-computed-attributes","free":true,"listed":false,"github":"https://github.com/korridor/laravel-computed-attributes","clone":"git clone https://github.com/korridor/laravel-computed-attributes.git","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.","language":"PHP","stars":12,"topics":["laravel","package","performance","eloquent","model","caching","accessor","eloquent-models","database"],"license":"MIT","category":"databases-storage","readme_excerpt":"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: - 13. (PHP 8.3, 8.4) - 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 ","default_branch":null,"files":null,"tree":[],"storefront":"/r/korridor","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/korridor/laravel-computed-attributes/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}