Call to a member function title() on string

Hello, I have an events page where I would like the client to be able to add categories to each event, I have managed to do this with my blueprint

tabs:
  content:
    columns:
    label: Page Content
    fields:
      eventCategories:
        label: Categories that events can be filtered by.
        type: tags
        sort: asc
      events:
        type: structure
        label: Upcoming Events
        sortBy: startdate desc
        fields:
          title:
            label: Event Title
            type: textarea
         category:
            label: Type of Event
            type: select
            width: 1/2
            default: All
            options:
              type: query
              query: page.eventCategories.split

This all works, I then have a filter block that uses Alpine.js but I am getting an error
This is the filter block

<div x-data="{ tab: 'all' }">
  <div class="sort">
    <ul class="sort--links">
    <?php foreach ($page->eventCategories()->split() as $item):  ?>
      <li class="link--item">
        <a href="#" @click.prevent="tab = '<?= $item->title()->lower() ?>'" :class="{ 'active' : tab === 'all' }"><?= html($item->title()) ?></a>
      </li>
    <?php endforeach ?>
    </ul>
  </div>

And I get the error 'Call to a member function title() on string`, I have also tried <?= $item->value()->lower() ?> which doesn’t work either.

I am successfully calling in the category with this code further down the same page

   <?php $events = $page->events()->toStructure();
    $sortedEvents = $events->filter(function ($child) {
    return $child->startdate()->toDate() > time() && $child->enddate()->toDate() < time();
    })->flip();
    foreach ($sortedEvents as $item): ?>
    <div class="event--block" x-show="tab === '<?= $item->category()->lower() ?>' || tab === 'all'">: ?>

Any help would be appreciated.

$item is just a string, you cannot call a field method like title() on this

But you need to call toStructure() on eventCategories, not split, to convert the structure field to a Structure object.

Ah, that works, thank you, is there a way to output the string as lowercase? I get an error if I use $item()->lower()

What code do you have now?

<ul class="sort--links">
<?php foreach ($page->eventCategories()->split() as $item): ?>
  <li class="link--item">
    <a href="#" @click.prevent="tab = '<?= $item ?>'" :class="{ 'active' : tab === 'all' }"><?= html($item) ?></a>
  </li>
<?php endforeach ?>
</ul>

Sorry!

You can use Str::lower($item)

Thank you, it works perfectly now.