Livewire test, set array value

What seems to be the problem:
I have an array of models in a public property (called answers) in my Livewire component. I am writing tests for the component but I don’t know how to set the array values. I have tried using dot notation but it throws an exception.
Livewire\Exceptions\CannotBindDataToEloquentModelException : Cannot bind Eloquent model using [wire:model="answers.0.title"].

Steps to Reproduce:

            ->set('answers.0.title', 'blue')

Are you using the latest version of Livewire:

Do you have any screenshots or code examples:
Code example above.

I have managed to resolve this now by updating the assignment in the mount() method so it converts the collection of models to an array.


$this->answers = $question->answers;


$this->answers = $question->answers()->exists() ? $question->answers->toArray() : [];

1 Like