min/fractalcommands

Laravel commands for fractal
42
Install
composer require min/fractalcommands:dev-master
License:MIT
Last Updated:Mar 17, 2017
Links: GitHub  ·  Packagist
Maintainer: leexikang

Fractal-commands commands for using Fractal on Laravel's project.

For more about Fractal Please go to Fractal Document.

Install

composer require min/fractalcommands
add service provider

dd class to config/app.php

Min\FractalCommands\FractalCommandsServiceProvider::class
Commands
  • php artisan fractal:init (create App/Api/Tranformer/ and Controllers/ApiControler)
  • php artisan tranformer:create {Tranformer} --model={model} (Create Tranformer in App\Api\Tranformer)

Usages

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.

$this->transform(Post::all(), new PostTransformer); 

To tranform single item (model), use tranform command

$this->transform(Post::find(1), new PostTransformer); 

:warning: Call the parenet's (ApiController) constructor if you want to extend the Controller's constructor

parent::__construct(); 

The tranformer:create command will create the layout for your Tranformer in the App/Api/Tranformer Directory.

Licence

MIT

Related Packages

gathercontent/laravel-fractal

A Laravel Service Provider for Fractal

162,611 50
lyhty/commands

Adds some very convenient commands to your Laravel project

8,749 2
velcoda/commands

Artisan Commands to help devs

6,636 0
m4tthumphrey/fractal-laravel

Laravel bindings for the Fractal library.

2,564 4
kilrizzy/user-commands

L5 Commands for Generating Users and Roles

18 0