Wallogit.com
2017 © Pedro Peláez
Laravel commands for fractal
For more about Fractal Please go to Fractal Document., (*1)
composer require min/fractalcommands
dd class to config/app.php, (*2)
Min\FractalCommands\FractalCommandsServiceProvider::class
php artisan tranformer:create {Tranformer} --model={model} (Create Tranformer in App\Api\Tranformer), (*3)
To use fractal on your controller, extend the Controller first which is created by the fractal:init command. Then call the tranform method povided by the Api Controller and pass the Sepcific tranformer class., (*4)
$this->transform(Post::all(), new PostTransformer);
To tranform single item (model), use tranform command, (*5)
$this->transform(Post::find(1), new PostTransformer);
:warning: Call the parenet's (ApiController) constructor if you want to extend the Controller's constructor, (*6)
parent::__construct();
The tranformer:create command will create the layout for your Tranformer in the App/Api/Tranformer Directory., (*7)
MIT, (*8)