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 ^^
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.
In my case is the third party API has an endpoint that provides their data. so I made a request then loop each data, and if I got 400 data, on each loop I do some validation and update. will it cause problems in the future?
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?
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.