eventhomes/laravel-fractalhelper

Compatible with Laravel 5+ and Lumen 5+.
88,771 7
Install
composer require eventhomes/laravel-fractalhelper
Latest Version:2.0.1
PHP:^7.2
License:MIT
Last Updated:Jan 28, 2020
Links: GitHub  ·  Packagist
Maintainer: lostincode

Laravel 5 / Lumen 5 Fractal Api Controller

A simple api controller helper utilizing league fractal. You also get all the functionality provided by https://github.com/eventhomes/laravel-apicontroller

Installation

composer require eventhomes/laravel-fractalhelper

Basic Usage

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', ''));
    }
}

Customize Fractal

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', ''));
    }
}

Respond with item

public function show($id)
{
    $user = User::find($id);
    return $this->respondWithItem($user, new UserTransformer);
}

Respond with collection

public function index()
{
    $users = User::all();
    return $this->respondWithCollection($users, new UserTransformer);
}

Respond with collection, paginated

public function index()
{
    $users = User::paginate(10);
    return $this->respondWithCollection($users, new UserTransformer);
}

Related Packages

ftxrc/apicontroller

Simplified API controller, inspired by Jeffrey Way. Compatible with Laravel 5+ a...

37 2
eventhomes/laravel-apicontroller

Simplified API controller, inspired by Jeffrey Way. Compatible with Laravel 5+ a...

94,257 7
viodev/laravel-replier

Laravel package for making JSON APIs.

16,278 1
carvinglabs/laravel-fractal

A Fractal service provider for Laravel 5

639 0
spatie/laravel-fractal

An easy to use Fractal integration for Laravel applications

17,105,565 1,905

Version History

Version Released PHP License
2.0.1 ^7.2 MIT
2.0.0 ^7.2 MIT
v1.1.0 ^7.2 MIT
v1.0 ^7.2 MIT
v0.1.5 ^7.2 MIT