src/Gzero/Api/Controller/ApiController.php
protected function respondTransformer($data, $code, TransformerAbstract $transformer, array $headers = [])
    {
        if ($data === null) { // If we have empty result
            return $this->respond(
                [
                    'data' => []
                ],
                $code,
                $headers
            );
        }

        if ($data instanceof LengthAwarePaginator) { // If we have paginated collection
            $resource = new Collection($data->items(), $transformer);
            return $this->respond(
                [
                    'meta'   => [
                        'total'       => $data->total(),
                        'perPage'     => $data->perPage(),
                        'currentPage' => $data->currentPage(),
                        'lastPage'    => $data->lastPage(),
                        'link'        => \URL::current()
                    ],
                    'params' => $this->processor->getProcessedFields(),
                    'data'   => $this->getSerializer()->createData($resource)->toArray()
                ],
                $code,
                $headers
            );
        } elseif ($data instanceof LaravelCollection) { // Collection without pagination
            $resource = new Collection($data, $transformer);
            return $this->respond(
                [
                    'data' => $this->getSerializer()->createData($resource)->toArray()
                ],
                $code,
                $headers
            );
        } else { // Single entity
            $resource = new Item($data, $transformer);
            return $this->respond(
                $this->getSerializer()->createData($resource)->toArray(),
                $code,
                $headers
            );
        }
    }
protected function respondTransformer($data, $code, TransformerAbstract $transformer, array $headers = [])
    {
        if ($data === null) { // If we have empty result
            return $this->respond(
                [
                    'data' => []
                ],
                $code,
                $headers
            );
        }

        if ($data instanceof LengthAwarePaginator) { // If we have paginated collection
            $resource = new Collection($data->items(), $transformer);
            return $this->respond(
                [
                    'meta'   => [
                        'total'       => $data->total(),
                        'perPage'     => $data->perPage(),
                        'currentPage' => $data->currentPage(),
                        'lastPage'    => $data->lastPage(),
                        'link'        => \URL::current()
                    ],
                    'params' => $this->processor->getProcessedFields(),
                    'data'   => $this->getSerializer()->createData($resource)->toArray()
                ],
                $code,
                $headers
            );
        } elseif ($data instanceof LaravelCollection) { // Collection without pagination
            $resource = new Collection($data, $transformer);
            return $this->respond(
                [
                    'data' => $this->getSerializer()->createData($resource)->toArray()
                ],
                $code,
                $headers
            );
        } else { // Single entity
            $resource = new Item($data, $transformer);
            return $this->respond(
                $this->getSerializer()->createData($resource)->toArray(),
                $code,
                $headers
            );
        }
    }
protected function respondTransformer ( $ data , $ code , TransformerAbstract $ transformer , array $ headers = [ ] ) { if ( $ data === null ) { // If we have empty result return $ this -> respond ( [ 'data' => [ ] ] , $ code , $ headers ) ; } if ( $ data instanceof LengthAwarePaginator ) { // If we have paginated collection $ resource = new Collection ( $ data -> items ( ) , $ transformer ) ; return $ this -> respond ( [ 'meta' => [ 'total' => $ data -> total ( ) , 'perPage' => $ data -> perPage ( ) , 'currentPage' => $ data -> currentPage ( ) , 'lastPage' => $ data -> lastPage ( ) , 'link' => \ URL :: current ( ) ] , 'params' => $ this -> processor -> getProcessedFields ( ) , 'data' => $ this -> getSerializer ( ) -> createData ( $ resource ) -> toArray ( ) ] , $ code , $ headers ) ; } elseif ( $ data instanceof LaravelCollection ) { // Collection without pagination $ resource = new Collection ( $ data , $ transformer ) ; return $ this -> respond ( [ 'data' => $ this -> getSerializer ( ) -> createData ( $ resource ) -> toArray ( ) ] , $ code , $ headers ) ; } else { // Single entity $ resource = new Item ( $ data , $ transformer ) ; return $ this -> respond ( $ this -> getSerializer ( ) -> createData ( $ resource ) -> toArray ( ) , $ code , $ headers ) ; } }
Return transformed response in json format

@param mixed               $data        Response data
@param int                 $code        Response code
@param TransformerAbstract $transformer Transformer class
@param array               $headers     HTTP headers

@return \Illuminate\Http\JsonResponse
Return transformed response in json format