如何访问Laravel回复

时间:2018-01-16 15:42:51

标签: json laravel eloquent response

我使用API​​作为信用卡验证器,我在Controller上写道:

dd($ChargeResponse);

我得到了这些数据:

enter image description here

如何访问此对象?

我尝试: $ChargeResponse->_email但是不行......

更新: 控制器:

$CardTokenChargePayload->setEmail($request->email);
$CardTokenChargePayload->setAutoCapture('N');
$CardTokenChargePayload->setAutoCaptime('0');
$CardTokenChargePayload->setValue('10000');
$CardTokenChargePayload->setCurrency('usd');
$CardTokenChargePayload->setTrackId('Demo-0001');
$CardTokenChargePayload->setCardToken($data['cko-card-token']);
try {
    /** @var RequestModels\CardTokenChargeCreate $CardTokenChargePayload **/
    $ChargeResponse = $charge->chargeWithCardToken($CardTokenChargePayload);
    //$ChargeResponse = json_encode($ChargeResponse);
    return collect($ChargeResponse);

} catch (checkout\helpers\ApiHttpClientCustomException $e) {
    echo 'Caught exception Message: ',  $e->getErrorMessage(), "\n";
    echo 'Caught exception Error Code: ',  $e->getErrorCode(), "\n";
    echo 'Caught exception Event id: ',  $e->getEventId(), "\n";
    return response()->json(['code' => '2000', 'message' => $e->getErrorMessage()]);
}

1 个答案:

答案 0 :(得分:2)

首先,"对象"不是一个真正的对象,是一个数组。所以你可以像这样打电话给你的道具:

$ChargeResponse['_emai']

但是如果你想转换它并使用Collections,你可以这样做:

$ChargeResponse = collect($ChargeResponse);

然后你可以使用

$ChargeResponse->_email