Skip to content

Creates "deflated" serialised arrays by using a dictionary of models that may be referenced more than once

License

Notifications You must be signed in to change notification settings

CaseElectronics/laravel-shrinkwrap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel-shrinkwrap

Creates 'deflated' serialised arrays by using a dictionary of models that may be referenced more than once

Installation

You can install the package via composer:

composer require zem/laravel-shrinkwrap

Laravel 5.5+ will automatically register the service provider(s).

Usage

Add the \ZEM\Shrinkwrap\Addressable trait to models you would like to have "deduplicated" in the serialisation process.

\ZEM\Shrinkwrap\Facility::shrink(collect([
    'item1' => $myModel,
    'item2' => $myModel,
]));

// Or using the built-in macro:

collect([
    'item1' => $myModel,
    'item2' => $myModel,
])->shrink();

If you have instances of addressable models at "deep" paths within your data, make sure each iterable item is a collection all the way down to the model as toArray will be called on each item.

Testing

composer test

About

Creates "deflated" serialised arrays by using a dictionary of models that may be referenced more than once

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages