繁体   English   中英

Laravel / Vue.js-试图获取非对象的属性。 可以在Vue中访问它,但不能访问Laravel

[英]Laravel/Vue.js - Trying to get property of non-object. Can access it in Vue but not Laravel

我遇到一个奇怪的问题,我似乎无法访问Laravel中的对象,但是将变量传递到Vue前端时,我可以访问其中的所有内容。

这是代码,这就是产生的代码...

 public function getPaymentStatus(Request $request) { $transaction = $this->midTest->getLatestTransaction(); $url = "https://" . $transaction->url . $request->resourcePath; $url .= "?authentication.userId=" . $transaction->user_id; $url .= "&authentication.password=" . $transaction->password; $url .= "&authentication.entityId=" . $transaction->entity_id; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // This should be set to true in production curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $responseData = curl_exec($ch); if(curl_errno($ch)) { return curl_error($ch); } curl_close($ch); return $responseData; } 

在此处输入图片说明

但是,如果执行此操作,则会出现错误。

 return $responseData->data; 

尝试获取非对象{“ exception”:“ [object]的属性'data'(ErrorException(code:0):尝试在/ Users / dallysingh / Projects / Laravel / app中获取非对象的属性'data' /Http/Controllers/MidTestController.php:196)

在我的Vue前端中,我可以console.log以下内容并清楚地看到所有数据。

 console.log(response.data); 

我要如何在Laravel中访问对象,因为我想做的就是将数据存储到表中,然后再将其发送到Vue前端。 这就是我要的...

 public function getPaymentStatus(Request $request) { $transaction = $this->midTest->getLatestTransaction(); $url = "https://" . $transaction->url . $request->resourcePath; $url .= "?authentication.userId=" . $transaction->user_id; $url .= "&authentication.password=" . $transaction->password; $url .= "&authentication.entityId=" . $transaction->entity_id; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // This should be set to true in production curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $responseData = curl_exec($ch); if(curl_errno($ch)) { return curl_error($ch); } curl_close($ch); $this->midTest->updateLatestTransaction($responseData, $transaction); return $responseData; } public function updateLatestTransaction($response, $transaction) { $transaction = DB::table('transactions') ->where('id', $transaction->id) ->update( ['transaction_id', $response->data['id'] ]); } 

$ responseData可能是PHP中的json字符串。

尝试

$responseDataDecoded = json_decode($responseData);

现在,变量$ responseDataDecoded是一个对象。

在laravel中,您还可以使用函数dd($ variable)转储变量。 例如,对于解码后的json字符串:

dd($responseDataDecoded);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM