php - Handling guzzle 6 response body in laravel -
i'm making laravel 5.2 project communicating local api. , i'm having issues handling guzzle response body.
my controller:
public function getclients(){ $guzzle = new client(); try{ $response = $guzzle->request('get', 'http://localhost:3000/client')->getbody(); return view('home.clients', ['clients' => $response]); }catch(clientexception $e){ //handling exception } }
my blade view:
<h2>client list</h2> {{ $clients }}//just inspect @forelse ($clients $client) <h3>{{ $client->name }}</h3> <h3>{{ $client->email }}</h3> <h3>{{ $client->country }}</h3> @empty <h3>no clients here</h3> @endforelse
no errors on loop or controller, showing stream object in browser in loop doesn't display anything.
i've read guzzle 6 response body documentation, it's not clear newbie in me.
thoughts?
browser output:
you have decode json json_decode()
:
public function getclients(){ $guzzle = new client(); try { $response = json_decode($guzzle->request('get', 'http://localhost:3000/client')->getbody()); return view('home.clients', ['clients' => $response]); } catch(clientexception $e){ //handling exception } }
and can remove {{ $clients }}//just inspect it
view.
more info json , guzzle here: guzzle 6: no more json() method responses
Comments
Post a Comment