src/Http/Controllers/Controller.php
public function success($data, $code = 200)
    {
        $headers = [];

        if ($data instanceof Paginator && $data instanceof LengthAwarePaginator) {
            $headers['X-Total-Count'] = $data->total();
            $headers['X-Total-Pages'] = $data->lastPage();
            $headers['X-Total-Current'] = $data->currentPage();

            // We only set this if the current page is not the last one
            if ($data->currentPage() < $data->lastPage()) {
                $headers['X-Page-Next'] = $data->currentPage() + 1;
            }

            // We only set this if the current page is not the first one
            if ($data->currentPage() > 1) {
                $headers['X-Page-Previous'] = $data->currentPage() - 1;
            }

            $data = $data->items();
        }

        return Response::json($data, $code, $headers, JSON_PRETTY_PRINT);
    }
public function success($data, $code = 200)
    {
        $headers = [];

        if ($data instanceof Paginator && $data instanceof LengthAwarePaginator) {
            $headers['X-Total-Count'] = $data->total();
            $headers['X-Total-Pages'] = $data->lastPage();
            $headers['X-Total-Current'] = $data->currentPage();

            // We only set this if the current page is not the last one
            if ($data->currentPage() < $data->lastPage()) {
                $headers['X-Page-Next'] = $data->currentPage() + 1;
            }

            // We only set this if the current page is not the first one
            if ($data->currentPage() > 1) {
                $headers['X-Page-Previous'] = $data->currentPage() - 1;
            }

            $data = $data->items();
        }

        return Response::json($data, $code, $headers, JSON_PRETTY_PRINT);
    }
This method returns json for a successful request.
If $data is paginated, the pagination info will be added in headers.

@param $data
@param int $code
@return \Symfony\Component\HttpFoundation\Response