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

mehdi79's avatar

Why Livewire component not working inside <td> of table?

I have users table and inside table rows, I use edit-user component to load a modal.

when I use this edit-user component inside <td> tags, wire:key is messed up and edit-user component is not loading in every row and functionality of pagination and search broke.

but when using it out of <td> tags even <tr>, it works without problem.

Table Rows: (edit section)

@foreach($users as $user)
<tr class="border hover:bg-gray-100/40 text-sm" wire:key="{{$user->id}}">
    <td class="py-4 px-1 text-center">
            <input wire:model.live="selectedUserIds" value="{{$user->id}}" type="checkbox" class="rounded p-2 shadow">
    </td>
    
    <td class="whitespace-nowarp px-2 text-sm">
        <div class="flex items-center justify-end" x-data="{edit_modal: false }">
            <x-menu>
                <x-menu.button class="hover:bg-gray-200 hover:rounded">
                    <x-icon.ellipsis-horizontal :size="7"/>
                </x-menu.button>

                <x-menu.items>

                    @if($user->id !== session('user_id'))
                    <x-menu.item wire:click="activate({{$user->id}})">
                        {{$user->is_active === 1 ? 'غیرفعال‌سازی' : 'فعال‌سازی'}}
                    </x-menu.item>
                    @endif


                    <!-- edit -->
                    <livewire:tables.authentication.users.edit-user  :key="'row-'.$user->id" :$user/>
                    


                    <x-menu.item x-on:click=" edit_modal= true ">
                        لاگ
                    </x-menu.item>

                </x-menu.items>
            </x-menu>
        </div>

    </td>
</tr>

@endforeach
0 likes
6 replies
jaseofspades88's avatar

You are multiplying the component and not using wire:key on your respective component. Livewire can't tell the difference between your components.

Snapey's avatar

When you say wire:key is messed up, which key and how do you know it is messed up?

Not a good idea to have a component per row and a modal per row.

Is the outer table also a component? I ask because you have lots of use of wire: outside of your component.

The best solution is to have a single user edit component on the page, and then a button that tells the edit component to show, and for which user.

mehdi79's avatar

@Snapey yes I use it inside another component, It's what caleb porzio does in his screencasts but in that videos there is no pagination or other options when nesting table rows.

Please or to participate in this conversation.