Download the PHP package worksome/model-attributes without Composer
On this page you can find all versions of the php package worksome/model-attributes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download worksome/model-attributes
More information about worksome/model-attributes
Files in worksome/model-attributes
Package model-attributes
Short Description Model attributes are dynamically generated data on models added as a relationship.
License MIT
Homepage https://github.com/worksome/model-attributes
Informations about the package model-attributes
Model attributes are dynamically generated values for models. They are used as eloquent relationships which can be eager loaded.
Installation
You can install the package via composer:
Usage
Assuming we have the following table structure:
And the following models:
We can add a rating
property to each user that is the calculated average of a users reviews. First we're going to create a Model attribute:
and add it as a relationship to the user model
So that it can be used like so:
Since model attributes are essentially dynamically generated data, and the rating is a scalar, we can override the getValue()
method of a model in order to "reach" the rating faster:
And now the rating can be accessed like so:
And because it's a relationship it can be eager loaded:
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
- Marian Hodorogea
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of model-attributes with dependencies
spatie/laravel-package-tools Version ^1.14.1
illuminate/contracts Version ^9.46|^10.0