kenmulford / generators by kenmulford

Extend Laravel 5's generators.
26
0
2
Package Data
Maintainer Username: kenmulford
Maintainer Contact: ken@kenmulford.com (Ken Mulford)
Package Create Date: 2015-04-07
Package Last Update: 2015-04-10
Language: PHP
License: MIT
Last Refreshed: 2024-03-26 03:11:30
Package Statistics
Total Downloads: 26
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 2
Total Forks: 1
Total Open Issues: 0

Laravel 5/Fractal Transformer Generator

This extends the php artisan command list to include a command for generating a basic Fractal transformer based on your existing Eloquent model.

Usage

Step 1: Install Via Composer

composer require 'mulford/generators' --dev

Step 2: Register the Service Provider

Open config/app.php and add the line to the bottom of your providers array:

"Mulford\Generators\TransformerGeneratorServiceProvider"

Step 3: Run Artisan

Run php artisan list from the console and you will see make:transformer in the "make" section.

Defaults

By default, this library references models in the App\Models namespace (not the Laravel 5 default of App). It creates new Transformer classes in App\Transformers. In a future version I will try to make this a config option.

Example

php artisan make:transformer --model=User

This command will create a basic Fractal Transformer class with some placeholders, as well as a basic transform() method. By default the transform() object array is populated based on the Eloquent model's $fillable property. Obviously you can tweak the list as desired, but it serves as a decent starting point.

Future

Eventually I hope to work out a way to create includes based on Eloquent relationships. If you are interested in helping feel free to send a pull request!