Save data from Rest API in database and check whether to update
Hello Guys!
I am creating some functionality that is to retrieve data from an external API and save it in the database. Overall, this is a product list. I have to download and save this data because the devices on which it will be displayed work offline due to poor internet speed and the data update is to be performed once an hour.
I am currently using Guzzle, I am downloading the data without any problems, I just don't know how to check if the data has changed and update it? Use UpdateOrCreate? Do you have any better ideas? I was looking for some examples on the web but I didn't find anything special, maybe you have some nice articles?
@sinres I’m a little confused as to the workflow here. Is the API yours or a third party?
Usually with apps that need to work offline, they get their data from an API. So it sounds like you’re fetching product data from an API, to put in a database, that an app would then fetch via another API…?
If you want to sync product data (or any data), then you’ll need to save them in local storage on the device. You can then use this last sync time as a delta to query for any new or updated products the next time the device gets connectivity. Just fetch any products with an updated_at timestamp greater than your “last synced at” timestamp.