Search code examples
laravellaravel-controllerlaravel-api

How to Get data from an API every 2 min and use it in all of project?


I want to build a website which need to get gold price every 3 min and use with this price in many of my controller in my project. how can get gold price from another API and how use this in my controller?


Solution

  • use cronjob to send a request to the gold api, receive the results and save them to the databse, and after 3 minute check if the price for the gold exists, update price. After you have the data you can access it from all your controllers and methods.

    Laravel Cron jon - Read here

    Laravel HTTP Client - Read here

    This is all you need to know to finish your task