2017-07-13 16 views
0

(2番目の配列)をループで$post->user->nameとループ表示できますが、3番目の配列データをどのように表示できますか? $post->likes->user_idとして機能しません。
助けてください。ここ
は私の配列のリストである:あなたが使用することはできませんアレイではlaravelの多次元配列

[{ 
    "id": 13, 
    "user_id": 1, 
    "content": "\"The reason most people never reach their goals is that they don't define them, or ever seriously consider them as believable or achievable. Winners can tell you where they are going, what they plan to do along the way, and who will be sharing the adventure with them.\" --Denis Waitley", 
    "status": 0, 
    "created_at": "2017-07-06 04:02:41", 
    "updated_at": "2017-07-06 04:02:41", 
    "user": { 
     "id": 1, 
     "name": "hardeep singh", 
     "gender": "male", 
     "slug": "hardeep-singh", 
     "email": "[email protected]", 
     "pic": "47224964-profile-pictures.jpg", 
     "role": "admin", 
     "created_at": "2017-02-21 06:06:28", 
     "updated_at": "2017-02-21 06:06:28" 
    }, 
    "likes": { 
     "id": 2, 
     "posts_id": 13, 
     "user_id": 3, 
     "created_at": "2017-07-07 17:52:18" 
    } 
}, { 
    "id": 12, 
    "user_id": 10, 
    "content": "\"People who succeed have momentum. The more they succeed, the more they want to succeed, and the more they find a way to succeed. Similarly, when someone is failing, the tendency is to get on a downward spiral that can even become a self-fulfilling prophecy.\" --Tony Robbins", 
    "status": 0, 
    "created_at": "2017-07-06 04:00:14", 
    "updated_at": "2017-07-06 04:00:14", 
    "user": { 
     "id": 10, 
     "name": "Ogran Gysn", 
     "gender": "male", 
     "slug": "ogran-gysn", 
     "email": "[email protected]", 
     "pic": "ee.jpg", 
     "role": "company", 
     "created_at": "2017-03-10 10:48:19", 
     "updated_at": "2017-03-10 10:48:19" 
    }, 
    "likes": { 
     "id": 3, 
     "posts_id": 12, 
     "user_id": 3, 
     "created_at": "2017-07-07 17:52:33" 
    } 
}, { 
    "id": 11, 
    "user_id": 9, 
    "content": "\"Thinking should become your capital asset, no matter whatever ups and downs you come across in your life.\" --A.P.J. Abdul Kalam", 
    "status": 0, 
    "created_at": "2017-07-06 03:59:47", 
    "updated_at": "2017-07-06 03:59:47", 
    "user": { 
     "id": 9, 
     "name": "john lewis", 
     "gender": "male", 
     "slug": "john-lewis", 
     "email": "[email protected]", 
     "pic": "scs.png", 
     "role": "company", 
     "created_at": "2017-03-10 04:04:27", 
     "updated_at": "2017-03-10 04:04:27" 
    }, 
    "likes": { 
     "id": 17, 
     "posts_id": 11, 
     "user_id": 1, 
     "created_at": "2017-07-13 10:07:56" 
    } 
}, { 
    "id": 10, 
    "user_id": 3, 
    "content": "Happiness is a butterfly, which when pursued, is always beyond your grasp, but which, if you will sit down quietly, may alight upon you", 
    "status": 0, 
    "created_at": "2017-07-06 03:59:19", 
    "updated_at": "2017-07-06 03:59:19", 
    "user": { 
     "id": 3, 
     "name": "anita donal", 
     "gender": "female", 
     "slug": "anita-donal", 
     "email": "[email protected]", 
     "pic": "47354305-profile-pictures.jpg", 
     "role": null, 
     "created_at": "2017-02-21 06:07:39", 
     "updated_at": "2017-02-21 06:07:39" 
    }, 
    "likes": { 
     "id": 13, 
     "posts_id": 10, 
     "user_id": 1, 
     "created_at": "2017-07-13 10:01:43" 
    } 
}, { 
    "id": 9, 
    "user_id": 1, 
    "content": "Take up one idea. Make that one idea your life--think of it, dream of it, live on that idea. Let the brain, muscles, nerves, every part of your body, be full of that idea, and just leave every other idea alone.", 
    "status": 0, 
    "created_at": "2017-07-06 03:58:40", 
    "updated_at": "2017-07-06 03:58:40", 
    "user": { 
     "id": 1, 
     "name": "hardeep singh", 
     "gender": "male", 
     "slug": "hardeep-singh", 
     "email": "[email protected]", 
     "pic": "47224964-profile-pictures.jpg", 
     "role": "admin", 
     "created_at": "2017-02-21 06:06:28", 
     "updated_at": "2017-02-21 06:06:28" 
    }, 
    "likes": { 
     "id": 19, 
     "posts_id": 9, 
     "user_id": 1, 
     "created_at": "2017-07-13 10:08:51" 
    } 
}, { 
    "id": 3, 
    "user_id": 9, 
    "content": "have a nic day :)", 
    "status": 0, 
    "created_at": "2017-07-05 07:59:22", 
    "updated_at": "2017-05-09 08:56:59", 
    "user": { 
     "id": 9, 
     "name": "john lewis", 
     "gender": "male", 
     "slug": "john-lewis", 
     "email": "[email protected]", 
     "pic": "scs.png", 
     "role": "company", 
     "created_at": "2017-03-10 04:04:27", 
     "updated_at": "2017-03-10 04:04:27" 
    }, 
    "likes": { 
     "id": 1, 
     "posts_id": 3, 
     "user_id": 1, 
     "created_at": "2017-07-13 10:33:43" 
    } 
}, { 
    "id": 1, 
    "user_id": 3, 
    "content": "This is demo post", 
    "status": 0, 
    "created_at": "2017-07-04 18:25:14", 
    "updated_at": "-0001-11-30 00:00:00", 
    "user": { 
     "id": 3, 
     "name": "anita donal", 
     "gender": "female", 
     "slug": "anita-donal", 
     "email": "[email protected]", 
     "pic": "47354305-profile-pictures.jpg", 
     "role": null, 
     "created_at": "2017-02-21 06:07:39", 
     "updated_at": "2017-02-21 06:07:39" 
    }, 
    "likes": null 
}, { 
    "id": 2, 
    "user_id": 3, 
    "content": "this is post by me, i am anita donal", 
    "status": 0, 
    "created_at": "2017-03-23 16:14:50", 
    "updated_at": "-0001-11-30 00:00:00", 
    "user": { 
     "id": 3, 
     "name": "anita donal", 
     "gender": "female", 
     "slug": "anita-donal", 
     "email": "[email protected]", 
     "pic": "47354305-profile-pictures.jpg", 
     "role": null, 
     "created_at": "2017-02-21 06:07:39", 
     "updated_at": "2017-02-21 06:07:39" 
    }, 
    "likes": { 
     "id": 21, 
     "posts_id": 2, 
     "user_id": 1, 
     "created_at": "2017-07-13 10:36:30" 
    } 
}] 
+0

あなたははい私はそのは –

+0

を定義しました$ post-> user-> name でも、好きなものを表示できません - $ post-> likes-> user_id foreach($ posts as $ post){ $ post ['like'] ['user_id'] } しかし動作しません – hardeepcoder

答えて

1

- >私はあなたの配列が$ポストオブジェクトであると仮定しています。

$post->likes->user_id. 
    foreach($post as $row){ 
      $row['like']['user_id'] 
    } 
+0

一緒に来るが、私は私たちのVUE使用しています post.user.nameのようなユーザからのデータを表示するので、私ができるか理由ですそれらの間の関係を定義@MichaelChenそれらの間の関係 – hardeepcoder