Compatible with Laravel 5+ and Lumen 5+.
eventhomes/laravel-fractalhelper is a Laravel package for compatible with laravel 5+ and lumen 5+..
It currently has 7 GitHub stars and 88.761 downloads on Packagist (latest version 2.0.1).
Install it with composer require eventhomes/laravel-fractalhelper.
Discover more Laravel packages by eventhomes
or browse all Laravel packages to compare alternatives.
Last updated
A simple api controller helper utilizing league fractal. You also get all the functionality provided by https://github.com/eventhomes/laravel-apicontroller
composer require eventhomes/laravel-fractalhelper
By default, this helper will use ArraySerializer(), no setup required. You may, however, need to parse the GET includes.
...
use EventHomes\Api\FractalHelper;
class MyController extends Controller {
use FractalHelper;
public function __construct(Request $request)
{
$this->parseIncludes($request->get('includes', ''));
}
}
If you need to change the default ArraySerializer(), you can modify.
...
use EventHomes\Api\FractalHelper;
class MyController extends Controller {
use FractalHelper;
public function __construct(Manager $manager, Request $request)
{
$manager->setSerializer(new JsonApiSerializer);
$this->setFractal($manager)->parseIncludes($request->get('includes', ''));
}
}
public function show($id)
{
$user = User::find($id);
return $this->respondWithItem($user, new UserTransformer);
}
public function index()
{
$users = User::all();
return $this->respondWithCollection($users, new UserTransformer);
}
public function index()
{
$users = User::paginate(10);
return $this->respondWithCollection($users, new UserTransformer);
}