我试图显示 json 响应 的值。当我在刀片视图内dd时,它工作得很好,但当我试图在桌子上显示时,它返回错误,这是@php dd( $user->irel__com_access_level->ID); @endphp尝试获取非对象的属性我的代码显示在表格中 @foreach($content as $user) <td>{{ $user->irel__com_access_level->ID }}</td> @endforeach这是我的 json 响应 ....我想显示irel__com_access_level内部的ID{ "data": [ { { "ID": "banana", "PWD": "W6ph5Mm5Pz8GgiULbPgzG37mj9g=", "NICK_NAME": "BANANA NANA NA", "PWD_INVALID_HIT": "0", "PWD_CREATE_DT": "2019/09/06 16:44:40", "INSTITUTION_ID": "C01", "ACL_ID": "L03", "LOGIN_DT": " ", "LOGIN_STS_ID": "N", "STS_ID": "C03", "TYPE_ID": "U00", "UPD_ID": "asmidah", "UPD_DT": "2019/09/06 16:44:40", "EMAIL_ID": "banana@gmail.com", "PHONE_NO_ID": "0", "HP_ID": "0101234567 ", "CRT_DATE_DELETED": "2019/09/06 16:44:40", "irel__com_access_level": { "ID": "L03", // i want to display this "DESCRIPTION": "2NDLEVEL", "IS_CREATE": "N", "IS_READ": "Y", "IS_UPDATE": "Y", "IS_DELETE": "N", "STS_ID": "R01", "UPD_ID": "shukrimb", "UPD_DT": "2012/09/13 13:28:25" }我的控制器 private $client; public function __construct(){ $this->client = new Client(['base_uri' => 'http://172.19.52.6/api/configuration/getUserIndex']); } public function index() { $response = $this->client->get('getUserIndex'); $content = json_decode($response->getBody()); return view('configuration.comuserprofiles.ComUserProfilesList', ['content' => $content->data]);我想在json响应中显示irel__com_access_level内部的ID
2 回答
MYYA
TA贡献1868条经验 获得超4个赞
试试这个
return view('configuration.comuserprofiles.ComUserProfilesList', ['content' => $content->data->first()]);
或
return view('configuration.comuserprofiles.ComUserProfilesList', ['content' => $content->data()->first()]);
慕尼黑8549860
TA贡献1818条经验 获得超11个赞
刚刚通过添加isset解决了这个答案
<td> @if(isset($user->irel__com_access_level)) @if(trim($user->ACL_ID) == trim($user->irel__com_access_level->ID)) {{ $user->irel__com_access_level->DESCRIPTION }} @endif @endif </td>
- 2 回答
- 0 关注
- 70 浏览
添加回答
举报
0/150
提交
取消