简体   繁体   中英

multidimensional array in laravel

I able to display user data (second array) in loop with $post->user->name but how can i display third array data ? it is not working as $post->likes->user_id .
Please help.
here is list of my array:

    [{
    "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": "hardeepphp@yahoo.com",
        "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": "ogran@gmail.com",
        "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": "john@gmai.com",
        "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": "anita@yahoo.com",
        "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": "hardeepphp@yahoo.com",
        "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": "john@gmai.com",
        "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": "anita@yahoo.com",
        "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": "anita@yahoo.com",
        "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"
    }
}]

In array you can't use -> i am assuming your array is in $post object.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM