I have the following code and when ever thevariable $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.
use Illuminate\Support\Collection;
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>