PHP code example of eventhomes / laravel-fractalhelper

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

    

eventhomes / laravel-fractalhelper example snippets


...
use EventHomes\Api\FractalHelper;

class MyController extends Controller {

    use FractalHelper;

    public function __construct(Request $request)
    {
        $this->parseIncludes($request->get('

...
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('

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