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

fikurimax's avatar

How can i do the synchronization data?

So I have hundreds of data in my SQL database, and I'd like to sync those data with the third party API whenever there are changes. how can I do it? can anyone please explain to me the flow and how to do it in Laravel using query builder or eloquent? thanks ^^

0 likes
7 replies
tykus's avatar

API >> You App

Unless the third party service provides webhooks whenever record(s) are updated, then you will likely need to poll the API for changes. If you do this, it would be helpful to have a way to query the API for records created or modified since the last time the synchronisation job was started - some APIs accept a If-Modified-Since header for this purpose. Once you can get the records, it is a matter of an updateOrCreate type query on each record from the API to put the data into your database.

Your App >> API

You can hook into the Eloquent model events (perhaps using an Observer) to send new or updated data to the API as the data is changed in your app. Or, you can batch this work similarly to the technique described above.

1 like
tykus's avatar

If there is no way to filter the API's data by a modified date, then you will need to poll for every record every time? Is there any opportunity to reduce the dataset?

fikurimax's avatar

not every time but once a day at midnight.

I want my data in sync with the third party API, so I don't reduce it

tykus's avatar

But every time you make that API call (at midnight every day; you will need to fetch every single record unless there is some way to ask only for the records that have been modified since yesterday at midnight.

fikurimax's avatar

Thanks, for your reply @tray2

but unfortunately, this way needs to install something which I can't due to hosting provider restrictions

Please or to participate in this conversation.