Accessing simple json response from external API not working in Laravel Controller

For example, the response that you get from the API looks like this

{
lead: [
{},
{},
{},
{},
{},
{},
{}
]
}

When you try to use access the leads value like below

$ssData->lead;

you will get this error

Undefined property: Illuminate\Http\JsonResponse::$lead

The solution you should do this way

$data = $ssData->getData();
// Then treat it as a regular json. For example...
$lead = $data->lead;

Leave a Comment