I would personally use an action to prepare the array I want to display. So you call this action and it prepares the data, with calculations and everything
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
Please or to participate in this conversation.