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

yu0307's avatar

Can laravel fetch data from remote API gateway instead of db?

Is Laravel even capable of handling microservices?

long question short; I was wondering if Laravel Eloquent model can fetch data from a remote API gateway other than a direct database connection setup in the config file, and still maintain the eloquent model capability, like m->get(), m->all(), m->where(), etc.... If you care about more details, please read the following detailed explanation.

Architecture setup:

  • Laravel app(s) at the front end, serving web application
  • one single API gateway for handling sub subsequent data requests. like getting data from cache microservice or getting data from a graphQL microservice, authentication microservice, etc.
  • maybe GuzzleHttp to communicate to API gateway to get data from

QUESTION: how to have the eloquent model file use external API as data source and fetch data via http(s) request and still maintain its functionalities?

0 likes
4 replies
yu0307's avatar

Hi, thank you for pointing that out, Does this also provide auto data fetching? I would assume this would require me to fetch the data first then serialize the result when instantiating the model object right? in scenario of modelA()->with('modelB')->get() will not work right? but thank you for the suggestion!

martinbean's avatar
Level 80

@yu0307 Eloquent is meant to work with relational databases. It’s an ORM.

jlrdw's avatar

@yu0307 either write the data (save) to database or use collections if the data is disposable.

Please or to participate in this conversation.