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

Thavo's avatar
Level 2

Livewire v3 + Laravel 11: How to Properly Show Validation Errors for Dynamic Arrays & Nested Components?

Hey everyone! šŸ‘‹

I've been running into a weird issue with Livewire v3 validation errors when working with nested components and dynamic array inputs. The validation errors exist, but they aren't being displayed properly in my Blade templates. 😩

Here’s what I tested so far, and I’m wondering: What’s the correct way to handle this in Livewire v3?

todo-list.blade.php

<div>
    <button wire:click="addTodo" class="bg-blue-500 text-white px-4 py-2 rounded">Add Todo</button>

    <ul class="mt-4 space-y-2">
        @foreach ($todos as $index => $todo)
            <livewire:todo-item 
                :todo="$todo" 
                :index="$index" 
                wire:key="todo-{{ $index }}" 
            />
        @endforeach
    </ul>

    <button wire:click="save" class="bg-green-500 text-white px-4 py-2 rounded mt-4">Save</button>
</div>

TodoItem

<?php

namespace App\Livewire;

use Livewire\Component;

class TodoItem extends Component
{
    public array $todo;
    public int $index;

    public function render()
    {
        return view('livewire.todo-item');
    }
}

todo-item.blade.php

I ran a dd($e->errors()) inside save() and got: array:1 [ā–¼ "todos.0.title" => array:1 [ā–¼ 0 => "O tĆ­tulo da tarefa Ć© obrigatório." ] ] So the validation is working āœ…, but Livewire isn’t displaying the error messages properly in the Blade template āŒ.

0 likes
1 reply
jj15's avatar

I believe the issue of the validation message not being displayed within the todo-item.blade.php view is because the $errors variable is scoped to the parent TodoList component, not the child TodoItem component where you're attempting to access them.

You can try splitting up your validation between both components. The parent should handle and validate adding a new todo, and the child should be responsible for handling and validating its editing.

Additionally, for the foreach loop in todo-list.blade.php, your wire:key should probably not be the index of the current iteration since it's not always technically unique. You would typically use the model ID for this, but you don't seem to be using any right now. Just something to be aware of.

Please or to participate in this conversation.