I have built a drop-down that dynamically populates a table depending on the option you have selected in the drop-down. The mount does the original query to get the options for the drop-down. I use updatedSelectedSite to hook into any change on the wire:model.live=‘selectedSite’ which is the drop-down. On any update the current $this->selectedSite value is used to get the site details to populate the table. Problem is on updating the drop-down the update takes 30 seconds and eloquent does 291 queries. In Livewire 2 this works fast and only performs one query.
Here is my component code.
class SitesTeams extends Component
{
public mixed $sites = null;
public ?int $selectedSite = null;
public ?Site $displaySite = null;
public function mount():void {
$this->sites = Site::query()->where('disabled', false)->orderBy('court_name')->get(['id','court_name']);
}
public function updatedSelectedSite():void {
$this->displaySite = Site::query()->where('id', $this->selectedSite)->with('teams')->first();
}
public function render()
{
return view('livewire.sites-teams');
}
}
The queries are made by
\vendor\livewire\src\Features\SupportModels\ModelSynth.php
Is there something I should be doing differently in Livewire 3?
Are you using the latest version of Livewire: yes 3.0.1