I am having Item (id, code, name & price), Warehouse(id & name) and Stock (item_id, warehouse_id, stock) models where Stock model is having item_id and warehouse_id relationship keys. I am trying to fetch items from stock model using livewire mount method
public $items, $selected_id;
public function mount()
{
$this->items = Stock::select('item_id', 'warehouse_id')->groupBy('item_id', 'warehouse_id')->get();
}
and I am using this items in livewire component’s select input
<select wire:model='selected_id'>
@foreach($items as $item)
<option value='{{$item->item->id}}'>{{$item->item->code}} - {{$item->item->name}} </option>
@endforech
</select>
This working perfectly fine on initial loading. but when I select a item from items select input, all items are lost and getting empty array in options.
I do not have idea on what is wrong in this code. Please help me to figure out the issue