PHP code example of gathercontent / laravel-fractal

1. Go to this page and download the library: Download gathercontent/laravel-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/ */

    

gathercontent / laravel-fractal example snippets


'providers' => array(
    // ...
    GatherContent\LaravelFractal\LaravelFractalServiceProvider::class
)

'aliases' => array(
    // ...
    'Fractal' => GatherContent\LaravelFractal\LaravelFractalFacade::class,
)

// routes.php
Route::get('/me', array('before' => 'auth', function () {
    return Fractal::item(Auth::user(), new UserTransformer);
}));

// routes.php
Route::get('/comments', function () {
    return Fractal::collection(Comment::all(), new CommentTransformer);
});

// routes.php
Route::get('/comments', function () {
    return Fractal::collection(Comment::all(), new CommentTransformer, function ($resources) {
        $resources->setMetaValue('foo', 'bar');
    });
});

// routes.php
Route::get('/comments', function () {
    return Fractal::collection(Comment::paginate(), new CommentTransformer);
});

// routes.php
Route::get('/comments', function () {
    $comments = Comment::paginate();
    $adapter = new MyIlluminatePaginationAdapter($comments);
    return Fractal::collection($comments, new CommentTransformer, null, $adapter);
});
bash
$ php artisan vendor:publish