Home > Enterprise >  Extending the Laravel Http Facade
Extending the Laravel Http Facade

Time:06-17

I'm trying to find the right way to extend the Laravel Http Client Facade. I don't want to do this every time when I want to get something from the response of my request. I would like to add some more helpers to prevent this. Also I can't directly extend the client, because I'm using the facade with a macro to ease my life.

    json_decode($this->getBody()->getContents())->id;

CodePudding user response:

This is already built into the client.

$response = Http::get('http://example.com/users/1');
$response->json()['id'];
$response->object()->id;

Or even:

Http::get('http://example.com/users/1')['id'];
  • Related