Download the PHP package dan-har/presentit-laravel without Composer
On this page you can find all versions of the php package dan-har/presentit-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dan-har/presentit-laravel
More information about dan-har/presentit-laravel
Files in dan-har/presentit-laravel
Package presentit-laravel
Short Description Transformers for nested Eloquent models and collection for building API with Laravel framework
License MIT
Informations about the package presentit-laravel
presentit-laravel
Presentit adapter for laravel framework.
Custom presentations and transformation of nested Eloquent models, models relations and collections.
See full presentit docs here
Docs
- Installation
- Transform Eloquent models
- Transform collections
- Transform nested models and relations
Installation
Install using composer
Add the presentit service provider to the app config file
Transform Eloquent models
Use presentit transformation functionality with any Eloquent model by implementing the contract and using the trait.
For example, the User model class with the PresentsItem trait
To transform the user model use the method to get a instance or use the method to use a transformer.
Instead of closure transformer you can pass a transformer class, see presentit docs or example below.
Transform collections
To transform collections the and macros were added to the base collection.
Model relations that returns collections such as HasMany will also have the presentit transformation functionality
The collection presentit api uses the method because the method exists in the base laravel collection.
Transform nested models and relations
To demonstrate the nested model transformation we will use an example of a Post with comments and on each comment users can write comments. So first we use a transformer class for the Post, Comment and User model
Then to transform a single post use
All versions of presentit-laravel with dependencies
illuminate/support Version 5.1.*|5.2.*|5.3.*|5.4.*
dan-har/presentit Version ^1.0