chustilla/cakephp-fractal

An easy to use Fractal integration for CakePHP 3 applications

2.2.0 2020-07-24 13:21 UTC

README

Basic data transformation for responding from your API.

The package provide a simple wrapper around Factral for your CakePHP 3 applications, inspired by Laravel fractal.

Requirements

  • PHP >=7.2

Installation

Via Composer

$ composer install chustilla/cakephp-fractal

Usage

For simpler usage, the package provide a helper

#src/Controller/VideoGamesController.php

public function index()
{
    return fractal(
        $this->VideoGames->find(),
        new VideoGameTransformer()
    )->respond();
}

where VideoGameTransformes is a Fractal Tranformer

For complex data structures you can use includes

fractal(
        $this->VideoGames->find()->contain([]),
        new VideoGameTransformer()
    )->parseIncludes(['platform'])
    ->respond();

License

The MIT License (MIT). Please see License File for more information.