Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

satheeshkumarj's avatar

Fetch value from Json sting

Given below is the dd of my output

Illuminate\Support\Collection {#1606 ▼
  #items: array:4 [▼
    0 => {#1597 ▼
      +"profile_setting": "[{"type":"Blood Donate","completion":"10","status":"1"},{"type":"Food Donate","completion":"15","status":"1"},{"type":"Clothes Donate","completion":"0","status" ▶"
      +"id": "3901ee9e-01bb-483a-9f74-8f7b76290cd5"
    }
    1 => {#1603 ▼
      +"profile_setting": "[{"type":"Blood Donate","completion":"10","status":"0"},{"type":"Food Donate","completion":"15","status":"1"},{"type":"Clothes Donate","completion":"0","status" ▶"
      +"id": "f2772366-4e7f-4257-90bd-8ea506dd8f84"
    }
    2 => {#1604 ▼
      +"profile_setting": "[{"type":"Blood Donate","completion":"10","status":"1"},{"type":"Food Donate","completion":"15","status":"1"},{"type":"Clothes Donate","completion":"0","status" ▶"
      +"id": "f8b20d31-ac80-4a98-b561-d255c79236fd"
    }
    3 => {#1607 ▼
      +"profile_setting": "[{"type":"Blood Donate","completion":"10","status":"1"},{"type":"Food Donate","completion":"15","status":"1"},{"type":"Clothes Donate","completion":"0","status" ▶"
      +"id": "15a31589-bba6-4e22-a5c2-1dcd13f43cfe"
    }
  ]
  #escapeWhenCastingToString: false
}

need to fetch id with 'Blood donation status 1'

0 likes
6 replies
Sinnbeck's avatar

@satheeshkumarj Ok so you want a list of the ids with status 1

$ids = $collection->filter(function($item) {
        return $item['profile_setting'][0]['status'] == 1; //not sure why profile_setting is an array and not an object..
})->pluck('id');
1 like
Snapey's avatar

If the data is actually json, you will need to map over the collection and json_decode each entry before deciding if it is the correct status

1 like

Please or to participate in this conversation.