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

Fiton012's avatar

Cannot assign array to property of type Illuminate\Support\Collection

I have the following code and when ever the variable $categoriesSelected that is of type Collection is updated on the DOM I am getting this error: "Cannot assign array to property App\Http\Livewire\ProductForm::$categoriesSelected of type Illuminate\Support\Collection"

Note that at first time it loads and works just fine. It's only when the the value is updated using the html select.

class ProductForm extends Component
{
    public Collection $categoriesSelected;
    public Collection $categories;
    public Product $product;

    public function mount(Product $product)
    {
        $this->product = $product;
        $this->categories = $product->categories()->get();
    }

   public function render()
    {
        return view('livewire.product-form');
    }
}
<select wire:model="categoriesSelected" multiple>
    @foreach($categories as $key => $value)
      <option value="{{ $key }}" wire:key="{{ $key }}">{{ $value }}</option>
    @endforeach
</select>
0 likes
5 replies

Please or to participate in this conversation.