Yaml and filterBy

Is there a way i can use filterBy() with yaml() to get only a specific value.
Lets say i’ve a list of clientdata and only want the phone-number back as an array.

I’m not sure what you mean:
It seems that you asked for a way how to get ALL the phone-numbers from a collection of pages (e.g. $page->children()). On the contrary, filterBy() would not do that, but filter a collection of pages to only include pages with ONE specific phone number. Which one do you actually want?

YAML fields are a lil but tricky, but usually there is a way to find a workaround.

I think what @danielschmid is looking to achieve is the following. Consider a structure field like this:

  name: James
  phone_number: 123456
  street: Sesamestreet 1
  name: John
  phone_number: 567890
  street: Sesamestreet 2


and grab only the phone numbers from the resulting yaml array and put them into a new array. So that would be a pluck rather than a filterBy, but for yaml fields.

Yea, that was what I was wondering. pluck isn’t possible for yaml fields as far as I’m aware. From an older project this might be an approach to a workaround:

$numbers = array_unique(array_map(function ($i) { return $i['phone_number']; }, $page->adresses()->yaml()));

thanks @distantnative and @texnixe. that looks good ill give it a try and keep you up to date. thanks