What seems to be the problem:
First time using Livewire (latest ver, new project in Larv8).
I have an Eloquent Collection of 'Companies" w/ related table ‘users’. On mount(), the LW view iterates over the companies making a Radio Btn for each. I am populating a Select List within the same LW view with ALL users from ALL companies. Everything works in the frontend on initial loading (companies and users show up in the DOM as expected).
Objective is to wire:click=“updateUserList” so that the companies_id is passed to the LW Component Class method ‘updateUserList’, and the public property ‘users’ is redefined by an Eloquent query for users where users.companies_id = [the radio button’s passed in value].
IT WORKS: If I dd() the users property from within the updateUserList($id) method, I see that it now reflects the user list that is associated with the radio button selected company.
PROBLEM: HOW CAN I GET THE users Select List Options to UPDATE and reflect the new values in the Component’s public property ‘users’? It never updates, even though I can see the public property’s data changed.
MORE INFO: I am using wire:modal=“users” on the element in the LW view. Both the radio buttons and the select list are within the same LW view.
LW COMPONENT CLASS METHOD: Called by wire:click on a radio button, passes in the companies ‘id’ value:
public function updateUserList( $companyId )
{
$this->users = \App\Models\user::where('companies_id', $companyId)->get();
//Displays the updated property 'users'
//DD($this->users);
}
LW VIEW (the radio buttons each with wire:click=""
<select name="users" wire:model="users" multiple >
@isset($users)
@foreach($users as $key=>$user)
@if(null !== $user)
<option value="{{$user->id}} name="id">
{{ $user->name }}
</option>
@endif
@endforeach
@endisset
</select>