Package Data | |
---|---|
Maintainer Username: | silverxjohn |
Maintainer Contact: | king.aldrin31@gmail.com (John Aldrin Plata) |
Package Create Date: | 2017-06-23 |
Package Last Update: | 2017-09-15 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-15 03:05:11 |
Package Statistics | |
---|---|
Total Downloads: | 552 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
A Fractal wrapper for Laravel
Fractal is designed in such a way that it could be used by any frameworks or no framework at all. But wouldn't it be cool if we can use it like it's build right on top of Laravel?
composer require plata/fravel
Then in your config/app.php
's provider array:
'providers' => [
// ...
'Plata\Fravel\FravelServiceProvider::class',
// ...
]
and within the same file,
'aliases' => [
// ...
''Fractal' => \Plata\Fravel\Facade\Fractal::class',
// ...
]
For a collection of resource,
$resource = Fractal::collection(User::all(), $transformer);
return Response::fractal($resource);
For a single resource,
$resource = Fractal::item(User::find(1), $transformer);
return Response::fractal($resource);
Everyone knows that developers doesn't like repetitive tasks. That's why generators are really helpful for creating a base template for you!
Existing Model and Migration
php artisan make:transformer UserTransformer
For non existing model/migration, just append -t
flag
php artisan make:model User -m -t
Fravel ships with a configuration file where you can change any Fractal specific behaviour. Just run:
php artisan vendor:publish
Need more control? Check this thorough documentation of Fravel.