envant / laravel-model-mutator
Load relations and append attributes from request query
1.1.4
2021-03-12 11:15 UTC
Requires
- php: ^7.1|^8
- illuminate/database: ~5.6.34|~5.7.0|~5.8.0|^6.0|^7.0|^8.0
- illuminate/http: ~5.6.34|~5.7.0|~5.8.0|^6.0|^7.0|^8.0
- illuminate/support: ~5.6.34|~5.7.0|~5.8.0|^6.0|^7.0|^8.0
Requires (Dev)
- ext-json: *
README
Load relations and append attributes from request query
Installation
Install package through Composer
$ composer require envant/laravel-model-mutator
Basic usage
Add Envant\ModelMutator\AllowedQueryMutationsTrait
trait to your model
Including relations based on a request: /?include=first_relation,second_relation
:
$model->allowedLoads([ 'firstRelation', 'secondRelation', ]);
Count relations based on a request: /?counts=first_relation,second_relation
:
$model->allowedCounts([ 'firstRelation', 'secondRelation', ]);
Appending attributes to a query: /?append=first_attribute,second_attribute
$model->allowedAppends([ 'firstAttribute', 'secondAttribute', ]);
Make attributes visible to a query: /?visible=first_attribute,second_attribute
$model->allowedVisible([ 'firstAttribute', 'secondAttribute', ]);
/?hidden=first_attribute,second_attribute
Make attributes hidden to a query: $model->allowedHidden([ 'firstAttribute', 'secondAttribute', ]);
Security
If you discover any security related issues, please email davidnadejdin@gmail.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.
Related packages
- spatie/laravel-query-builder Easily build Eloquent queries from API requests.