尝试在拉拉维尔中显示 json 响应值时获取非对象的属性

我试图显示 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


弑天下
浏览 71回答 2
2回答

MYYA

试试这个&nbsp;return&nbsp;view('configuration.comuserprofiles.ComUserProfilesList',&nbsp;['content'&nbsp;=>&nbsp;$content->data->first()]);或&nbsp;return&nbsp;view('configuration.comuserprofiles.ComUserProfilesList',&nbsp;['content'&nbsp;=>&nbsp;$content->data()->first()]);

慕尼黑8549860

刚刚通过添加isset解决了这个答案&nbsp;<td>&nbsp;&nbsp;&nbsp;&nbsp;@if(isset($user->irel__com_access_level)) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@if(trim($user->ACL_ID)&nbsp;==&nbsp;trim($user->irel__com_access_level->ID)) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{&nbsp;$user->irel__com_access_level->DESCRIPTION&nbsp;}}&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@endif &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@endif &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
打开App,查看更多内容
随时随地看视频慕课网APP