How to put the json results of guzzlehttp in blade view?

0

I have been reading for several hours, I have been investigating how to get the data from the http query with guzzle but I can not solve it. I need a little help on how the response received should be formatted. I want to treat the string as Json, not as XML. I appreciate if someone helps me with this. I'm working with Laravel 5.3.29. Here is the code of what I'm doing.

This is in my controller

    $client = new Client();
    $res = $client->request('GET','api.openweathermap.org/data/2.5/weather?zip=76140,us&APPID=5a66d84bcde9e22f0907fe5e52917649', [
        'param_form'=>[]
    ]);
    $restful_data=$res->getBody()->getContents();
    $posts=Post::orderBy('created_at','desc')->get();
    $view = View::make('dashboard',['posts'=>$posts])->with('restful_data',$restful_data);

    return $view;

I want to print everything for now just to try, or part of what arrives. This on my blade

<p>{{$restful_data}}</p>

And this is what I see coming from the http query

{"coord":{"lon":-97.29,"lat":32.63},"weather":[{"id":721,"main":"Haze","description":"haze","icon":"50d"}],"base":"stations","main":{"temp":298.84,"pressure":1006,"humidity":61,"temp_min":297.15,"temp_max":300.15},"visibility":16093,"wind":{"speed":6.2,"deg":120,"gust":10.3},"clouds":{"all":90},"dt":1490735700,"sys":{"type":1,"id":2624,"message":0.0081,"country":"US","sunrise":1490703650,"sunset":1490748435},"id":4689708,"name":"Everman","cod":200}

And the error I have when calling the route.

Whoops, looks like something went wrong.
1/1 FatalErrorException in postController.php line 40: Class 'App\Http\Controllers\View' not found
in postController.php line 40
    
asked by Erik 29.03.2017 в 19:41
source

0 answers