Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Extending the Laravel Http Facade

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;

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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'];
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading