Oliver Servín
Desarrollador y creador
Oliver Servín
19 de noviembre, 2021

Interact with API result values as object properties in Laravel

With the object method in the Laravel HTTP client, you can easily interact with API result values as object properties.

// https://api.adviceslip.com/advice response
// {
// "slip": {
// "id": 100,
// "advice": "Everybody makes mistakes."
// }
// }
 
$advice = Http::get('https://api.adviceslip.com/advice')->object();
 
$advice->slip->id; // 100
$advice->slip->advice; // Everybody makes mistakes.