Download the PHP package comhon-project/laravel-morphed-model-exporter without Composer
On this page you can find all versions of the php package comhon-project/laravel-morphed-model-exporter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download comhon-project/laravel-morphed-model-exporter
More information about comhon-project/laravel-morphed-model-exporter
Files in comhon-project/laravel-morphed-model-exporter
Package laravel-morphed-model-exporter
Short Description A laravel library that permit to export morphed models through an API
License MIT
Homepage https://github.com/comhon-project/laravel-morphed-model-exporter
Informations about the package laravel-morphed-model-exporter
Laravel Morphed Model Exporter
This library allows exporting morphed models (typically via an API). A morphed model is one that is loaded through a MorphTo
relationship. Since these models belong to different classes, loading them from a collection along with their dependencies and exporting them can be cumbersome. This library makes it easy!
Installation
You can install the package via composer:
Usage
Register exporters
In order to be able to export morphed models, you must define morphed model exporters.
To do so, you must define a class with an __invoke()
method that will return an array of exporters. Each key must be a eloquent model class and each value must be an array. Each array value must/may contain:
- the key
model_exporter
(required). The associated value must be either a Closure and return the exported model (the eloquent model is inject as parameter) either a JsonResource class. - the key
query_builder
(optional). The associated value must be a Closure that will build the query given in parameter.
Then you will have to register it in your AppServiceProvider
like this :
Load morphed models
You should typically load morphed models in Controllers :
You can use additional parameters to load differents data according a certain context :
Export morphed models
You should typically export morphed models in API resources :
You can use additional parameters to export differents properties according a certain context :
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- jean-philippe
- All Contributors
License
The MIT License (MIT). Please see License File for more information.