如何访问laravel集合中的属性值

I am getting data from multiple tables using eloquent relationship. here is my code:

 public function allPosts()
    {
        $posts = Post::with('commonContent','postComment','postLike')->get();
        //return $posts;
        foreach($posts as $post){
            echo $post->id;
            echo $post->content_id;

            foreach($post->common_content as $xyz){
              echo $xyz->description;
           }

        }
    }

when I return $posts I get this result:

[
{
id: 2,
user_id: 8,
content_id: 3,
title: null,
created_at: "2019-06-25 10:00:41",
updated_at: "2019-06-25 10:00:41",
common_content: {
id: 3,
description: "this is a post",
media_json: "{"image":"uploads\/j658XUVMuP2dutAgNUTpYvqLABkJLwYXkgX1zTai.png","video":"uploads\/wIsZNWVDZYZYOgdGstNA5dIsexpQAUu4zJo0wp0c.mp4","audio":"uploads\/2AjXxj1NgeUnUlsCkSAgVqgrykb4XwL8sbjin3cC.mpga"}",
created_at: "2019-06-25 10:00:41",
updated_at: "2019-06-25 10:00:41",
media_json_setting: {
image: "uploads/j658XUVMuP2dutAgNUTpYvqLABkJLwYXkgX1zTai.png",
video: "uploads/wIsZNWVDZYZYOgdGstNA5dIsexpQAUu4zJo0wp0c.mp4",
audio: "uploads/2AjXxj1NgeUnUlsCkSAgVqgrykb4XwL8sbjin3cC.mpga"
}
},
post_comment: [ ],
post_like: [ ]
}
]

here is my models:

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    protected $fillable = [
        'user_id', 'content_id'
    ];
    public function commonContent()
    {
        return $this->hasOne('App\Models\CommonContent', 'id','content_id');
    }

    public function postComment()
    {
        return $this->hasMany('App\Models\PostComment');
    }

    public function postLike()
    {
        return $this->hasMany('App\Models\PostLike');
    }

}

I am getting error "Invalid argument supplied for foreach()" on this foreach($post->common_content as $xyz). How can I access the properties. Any help would be highly appreciable.

$post->common_content as $xyz isn't an array, so you can not iterate over it via foreach. To access a property within $post->common_content you can do it via $post->common_content->property_name

On you example it would be for "description":

$post->common_content->description

commonContent is a one to one relation. It only retrieves one row instead of an array. So you can directly access its properties

echo $post->commonContent->description;