filterBy users structured field

I have this example field in my Users:

agenda:

  - local: Brasil
    date: de 9 a 10-jun

  - local: Argentina
    date: de 20 a 25-ago

  - local: Venezuela
    date: sob agenda

Now I want to list only the users that has ā€œagenda[ā€˜localā€™]ā€ == 'Brasilā€™
how to do that?

I tried this:

 $collection = $site->users()->filter(function($p) {
   return $p->toStructure()->agenda()->local() == 'Brasil';
 });

and this:

 $users = $site->users()->agenda()->toStructure()->filterBy('local', 'Brasil');

But none worksā€¦
Anyone can help me?! Thanks!

Try this:

$users = $site->users()->filter(function($user) {
  $agenda =  $user->agenda()->toStructure();
  return $agenda->local() == 'Brasil';
});

BTW: Please help to improve code readability by wrapping code blocks within three backticks at the beginning and the end of a block on a separate line. I have corrected your code above. To see how it works, click on the pencil icon of your post. Thank you.

Ok, did not work. I think it is something with being ā€œusersā€. I will test using pages to make sure it is a users problem (maybe toStructure dont work yet within users data).