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

webfuelcode's avatar

How to call API and get value in the controller

I am in need to do some mathematical calculations with the values in the controller and then the result on the blade page. I try to mention it here I hope to show you clearly.

Using API suppose http://api.someweb.com/uid/history This will show the currency price and the price history of a particular currency. Let say price and time. Here the price is okay but the time shows in seconds like this 1587639. So I have to convert it into a human-readable format. To make a line chart to show on my project page.

Here the price and the time are in array and I have to get the values to be calculated inside the controller. Because I am not using the database all the data are coming from other sites, I can not put mathematical calculations directly.

public function history()
{
	$collection = Http::get('http://api.someweb.com/uid/history');
	return view('coinprice', ['collection' => $collection]);
}

The above function will call price and time in an array. So I will use these on the blade page in foreach loop @foreach($collection as $item){{$item['price'] {{$item['time']}}@endforeach

The main problem is here how can I put the mathematical calculation in the same controller or may be different methods to show the result on my project page.

Suppose the specific currency API is http://api.someweb.com/uid/history And List of different currencies API is http://api.someweb.com/money/list

0 likes
1 reply

Please or to participate in this conversation.