1. Go to this page and download the library: Download cyvelnet/laravel5-fractal library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$user = User::find(1);
Fractal::item($user, new UserTransformer());
$users = User::where('activated', true)->get();
// $resourceKey is optional for most serializer, but recommended to set for JsonApiSerializer
$resourceKey = 'user';
Fractal::collection($users, new UserTransformer(), $resourceKey);
Fractal::
Fractal::excludes('orders')
Fractal::setSerializer(\Acme\MySerializer); // where MySerializer is a class extends \League\Fractal\Serializer\SerializerAbstract
// specify with single meta data
Fractal::addMeta($key = 'metaKey', $data = 'metaData')
// add an array of meta data
Fractal::addMeta([
'key1' => 'data1',
'key2' => 'data2'
])