Skip to content
Advertisement

Access data from a json array

I have this type of json object coming from a curl endpoint response:

[{"user":{"id":121153519,"full_name":"amresh12","email":null,"login":"amresh","phone":null,"website":null,"created_at":"2020-08-18T04:43:29Z","updated_at":"2020-08-25T04:04:21Z","last_request_at":"2020-08-25T04:04:22Z","external_user_id":null,"facebook_id":null,"twitter_id":null,"blob_id":null,"custom_data":null,"age_over16":false,"parents_contacts":"","user_tags":null}},{"user":{"id":121153974,"full_name":"ritu","email":null,"login":"ritu","phone":null,"website":null,"created_at":"2020-08-18T04:49:17Z","updated_at":"2020-09-07T01:03:24Z","last_request_at":"2020-09-07T01:03:25Z","external_user_id":null,"facebook_id":null,"twitter_id":null,"blob_id":null,"custom_data":null,"age_over16":false,"parents_contacts":"","user_tags":null}},{"user":{"id":121198739,"full_name":"abc","email":null,"login":"abc","phone":null,"website":null,"created_at":"2020-08-18T13:48:52Z","updated_at":"2020-08-30T05:26:12Z","last_request_at":"2020-08-30T05:26:57Z","external_user_id":null,"facebook_id":null,"twitter_id":null,"blob_id":null,"custom_data":null,"age_over16":false,"parents_contacts":"","user_tags":null}},{"user":{"id":121199492,"full_name":"Sleek","email":null,"login":"support@justsleek.co.za","phone":null,"website":null,"created_at":"2020-08-18T13:59:26Z","updated_at":"2020-08-30T05:31:37Z","last_request_at":"2020-08-30T05:31:38Z","external_user_id":null,"facebook_id":null,"twitter_id":null,"blob_id":null,"custom_data":null,"age_over16":false,"parents_contacts":"","user_tags":null}},{"user":{"id":121199660,"full_name":"Oupa","email":null,"login":"info@justsleek.co.za","phone":null,"website":null,"created_at":"2020-08-18T14:01:53Z","updated_at":"2020-08-18T15:49:51Z","last_request_at":"2020-08-18T15:49:51Z","external_user_id":null,"facebook_id":null,"twitter_id":null,"blob_id":null,"custom_data":null,"age_over16":false,"parents_contacts":"","user_tags":null}},{"user":{"id":121234544,"full_name":"J007","email":null,"login":"sumit","phone":null,"website":null,"created_at":"2020-08-18T18:34:07Z","updated_at":"2020-08-18T18:49:32Z","last_request_at":"2020-08-18T18:49:32Z","external_user_id":null,"facebook_id":null,"twitter_id":null,"blob_id":null,"custom_data":null,"age_over16":false,"parents_contacts":"","user_tags":null}},{"user":{"id":121712920,"full_name":"Generic User Master","email":"user@sleek.io","login":"user@sleek.io","phone":null,"website":null,"created_at":"2020-08-28T03:34:19Z","updated_at":"2020-10-01T13:28:37Z","last_request_at":"2020-10-01T13:28:34Z","external_user_id":null,"facebook_id":null,"twitter_id":null,"blob_id":null,"custom_data":null,"age_over16":false,"parents_contacts":"","user_tags":null}},{"user":{"id":121729914,"full_name":"Service Provider Master","email":"serviceprovider@sleek.io","login":"serviceprovider@sleek.io","phone":null,"website":null,"created_at":"2020-08-28T17:24:17Z","updated_at":"2020-09-30T18:16:12Z","last_request_at":"2020-09-30T18:16:10Z","external_user_id":null,"facebook_id":null,"twitter_id":null,"blob_id":null,"custom_data":null,"age_over16":false,"parents_contacts":"","user_tags":null}},{"user":{"id":121793428,"full_name":"a Six","email":"andile@justsleek.co.za","login":"andile@justsleek.co.za","phone":null,"website":null,"created_at":"2020-08-30T17:40:06Z","updated_at":"2020-09-07T17:31:50Z","last_request_at":"2020-09-07T17:31:50Z","external_user_id":null,"facebook_id":null,"twitter_id":null,"blob_id":null,"custom_data":null,"age_over16":false,"parents_contacts":"","user_tags":null}},{"user":{"id":121821276,"full_name":"Oupa S.P","email":"oupa@sleek.io","login":"oupa@sleek.io","phone":null,"website":null,"created_at":"2020-08-31T15:28:40Z","updated_at":"2020-09-02T05:56:17Z","last_request_at":"2020-09-02T05:56:34Z","external_user_id":null,"facebook_id":null,"twitter_id":null,"blob_id":null,"custom_data":null,"age_over16":false,"parents_contacts":"","user_tags":null}}]

i want to access full_name from that response and display it on my index.blade.php view page as a list of name like this:

 @foreach($users as $user)
    <div class="chat_list">
      <div class="chat_people">
        <div class="chat_ib">
           <h5>{{$user->full_name }}</h5>
        </div>
      </div>
   </div>
@endforeach

Please assist me to access the value from that array above.

Advertisement

Answer

You can do like this :

@php
   $users = json_decode($users, true);
@endphp
@foreach($users as $key => $val) 
   <div class="chat_list">
      <div class="chat_people">
        <div class="chat_ib">
           <h5>{{ $val['user']['full_name'] }}</h5>
        </div>
      </div>
   </div>
@endforeach

Above code tested here

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement