Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mrezende97's avatar

Using laravel native pagination in HTTP API microservices

Hello friends, I have a question about my project.

I'm building a laravel application based on independent microservices, but I'm having difficulty using laravel's native paginate to automatically paginate the results I receive from my api, below I leave an excerpt of my code:

....... MICRO SERVIÇO "ISSUES" ........

$query = Issue::query();

        if ($search) {
            $query->where('title', 'like', "%{$search}%");
        }

        $Issues = $query->paginate(10);

        if ($Issues) {
            return response()->json([
                'status' => 'success',
                'message' => "Issues successfully obtained",
                'data' => $Issues
            ], 200);
        }

...... MICRO SERVICE "FRONTEND" ......

$issues = Http::timeout(5) ->withToken($token) ->withHeaders([ 'Accept' => 'application/json', 'Content-Type' => 'application/json', ]) ->get(env('ISSUE_SERVICE_URL') . '/api/issues', [ 'search' => $this->search ]);

            if ($issues->successful()) {

                $logout = Http::timeout(5)
                    ->withHeaders([
                        'Accept' => 'application/json',
                        'Authorization' => "Bearer $token",
                    ])
                    ->post(env('USER_SERVICE_URL') . '/api/logout');

                if ($logout->successful()) {

                    return view('livewire.issue-table', ['issues' => $issues]);

                }

In short, the frontend microservice makes an http request to the issues microservice api, which in turn returns a response containing the data obtained from the database through eloquent already doing the pagination.

However, my difficulty is in making paging work in my view blade using the

{{ $issues->links() }}

I am having the error: Call to undefined method GuzzleHttp\Psr7\Response::links()

Could someone tell me what is wrong please?

0 likes
4 replies
RemiM's avatar

Currently, $issues comes from an HTTP API request and is a GuzzleHttp\Psr7\Response instance, which represents the raw HTTP response. Since this is not a Laravel paginator, it does not have a links() method, leading to the error.

To enable {{ $issues->links() }}, you need to manually transform the API response into a Laravel LengthAwarePaginator instance within your microservice’s frontend before passing it to the Blade view.

Snapey's avatar

first off, never use env() in your code. Change it to a config() item

Im not going to answer the main issue because this architecture is a really bad idea.

martinbean's avatar

In short, the frontend microservice makes an http request to the issues microservice api, which in turn returns a response containing the data obtained from the database through eloquent already doing the pagination.

Great. Now your users have to wait for two HTTP requests to complete instead of one before receiving their data.

jlrdw's avatar

I suggest just writing a regular web application.

Now if you are writing this for a Doctor's office and they have to get lab results from an API thats different. Just example.

Please or to participate in this conversation.