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

luisferfranco's avatar

Rendering Livewire components inside a loop. Which is the correct way?

I'm doing an administrative page for users. The page loads User::all() and displays it. No big deal. Now I to create a filter for name or email that matches certain criteria. So my I have a loadData() function that goes

$this->users = User::where('name', 'like', '%' . $this->busqueda . '%')
          ->orWhere('email', 'like', '%' . $this->busqueda . '%')
          ->orderBy('id')
          ->get();

So far, so good, when user types something in the search box, the list is filtered. the <input> in the HTML is:

This works fine.

Now, a user can have one of serveral "levels" that define if the user is authorized, if is an admin, etc. So in this panel I want a to select the level. I tried this:

  @foreach ($users as $user)
    <x-gui.tr>
      ...
      <td>
        <livewire:admin.user.selectlevel :user="$user" :key="$user->id" />
      </td>
      ...
    </x-gui.tr>
  @endforeach

The first time the page loads, it works perfectly, in the selectlevel component I have an unpdatedLevel() function that writes to the database, everithing works fine.

Now, if I filter the data, it stops working. The select shows for some rows and for some it doesn't. If I write something in the filter and then go back, it won't work either.

I got no idea what causes this, I don't know if it has to do with the rendering cycle, if I have to re-render the livewire component (I don't know how to do this), I don't know if the data that comes from the database renders slowly and I have to let it breathe, sort to speak (that's why I'm using the debounce), nothing seems to work for something as simple as this use case.

If using the select isn't the wiser thing, please advise how would you solve this

Thanks!

0 likes
4 replies
Snapey's avatar

do you also have wire key on the table rows?

luisferfranco's avatar

@Snapey on the <TR>? No... why should I? I mean... is it needed even when you don't have a component there?

The only key I'm using is in the component itself

<livewire:admin.user.selectlevel :user="$user" :key="$user->id" />

Then I thought maybe just a number for the ID wasn't enough, so I changed it to "sel-levl-" . $user->id but behaves the same

luisferfranco's avatar

@Snapey Oh no, it's not... its a component, but the one stored in components (blade?), not a livewire one

Please or to participate in this conversation.