I need to create a page that extract data which come from a third-party API. I can't find a way to change the data source in order to make a nova resource read data from the API, not from my database, is there a way to do that ?
-
1use guzzle http – bhucho Aug 24 '20 at 14:28
1 Answers
Laravel Nova Resources will only connect to a Laravel Model. However, there are ways to make a model represent an api using a mix of different packages and some ingenuity.
I would first set up a Saloon integration for connecting to and pulling from the API data. This isn't strictly necessary, but is a great way to keep your third-party API client clean.
I would use the saloon connectors/requests/responses in an Eloquent model that has the Sushi trait. This package allows a model to not be associated with a database table, and instead to use data returned from a method called getRows()
. Inside getRows()
is where I would connect to the API, consume what I needed to, and return the data.
Finally, I would use Laravels Model Events when saving or updating to send new data to the third-party api to update information.
This is high-level, and the details would be intricate so not appropriate for an SO answer - but hopefully this gets you moving in the right direction.

- 33
- 5