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

jpeterson579's avatar

How to use json data from api call in my view?

So I followed the curl tutorials on Laracasts and I am now returning Json data to a route.

So how the heck do I now grab the parts of it that I want, make it look pretty and return it to a view.blade?

array(25) { ["provider_url"]=> string(22) "http://www.nytimes.com" ["description"]=> string(314) "COLUMBUS, Ohio - Gov. John R. Kasich was sipping coffee in the sun-drenched garden room of his official residence, boasting about his "Ohio story" of economic recovery, when he was told that some Republicans thought a fellow Midwestern governor, Scott Walker of Wisconsin, was more conservative. He bolted upright." 
0 likes
3 replies
ATOM-Group's avatar
Level 11

So you're accessing the API through CURL on the server and not as JSON through an ajax call from javascript?

If that's the case, all you have to do is run $data = json_decode($data), and then View::make('view.blade', compact('data')) to access it normally.

1 like
jpeterson579's avatar

@tag So when i do that, in my blade i could so something like - {{ $description }}

ATOM-Group's avatar

Not quite, $data is an array, so you would access it like any normal array of data in PHP.

{{ $data['description'] }}

2 likes

Please or to participate in this conversation.