在 Laravel 中显示 json 响应的值时尝试获取 non-object 的 属性

Trying to get property of non-object when display value of json response in Laravel

我尝试显示 json 响应的值。当我在 blade 视图中添加 @php dd( $user->irel__com_access_level->ID); @endphp 时它运行良好,但是当我尝试在 table 显示时它 return 错误是

Trying to get property of non-object

我的代码显示在table

     @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

试试这个

 return view('configuration.comuserprofiles.ComUserProfilesList', ['content' => $content->data->first()]);

 return view('configuration.comuserprofiles.ComUserProfilesList', ['content' => $content->data()->first()]);

刚刚通过添加 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>