mosaiqo / optimus-prime
A simple package to transform collection and entities to output to a JSON / API.
Requires
- php: >=5.4.0
- illuminate/filesystem: ~5.1
- illuminate/support: ^5.1
- mustache/mustache: ~2.6
Requires (Dev)
- codeception/codeception: master-dev
- laravel/elixir: dev-master
- phpspec/phpspec: master-dev
This package is auto-updated.
Last update: 2024-11-04 19:22:33 UTC
README
Is a simple package to transform collection and entities TO a JSON - API before the response is returned to the requester. Think of it like the view presenter so you can adjust your output before, and maintain a clean API even if you change the DDBB structure.
Instalation
To install Mosaiqo Optimus Prime is really simple just install it with composer:
composer require mosaiqo/optimus-prime "dev-master"
after it just put this line in your laravel app/config.php file :
'Mosaiqo\OptimusPrime\TransformerServiceProvider',
now you can begin to play with your transformers.
How to transform your API
It's really easy to use Optimus Prime transformer.
In the model you want to use a transformer just have to implement the Mosaiqo\OptimusPrime\Decepticons
interface.
this interface forces you to use some methods to determine the transformer class.
But we have made it easy for you just pull in the Mosaiqo\OptimusPrime\Transformable
trait we have created.
<?php namespace Foo\Bar;
use Illuminate\Database\Eloquent\Model;
use Mosaiqo\OptimusPrime\Contracts\Decepticons;
use Mosaiqo\OptimusPrime\Transformable;
class Foo extends Model implements Decepticons
{
use Transformable;
}