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

lucas-dos-santos-silva's avatar

my livewire input component does not update after selecting something

I'm creating a searchable select component, where when typing and clicking on search it brings up the students in the tray, when clicking it should leave the student's name as the input value, but that doesn't happen, I tried to check the variables with dumps and dds, the value is assigned to the variables but it is not rendered in the view.

Livewire:

public $search = '';
public $students = [];
public $studentSelected = '';
public $showResults = false;
public $loading = false;

public function getStudents()
{
    if (strlen($this->search) >= 2) {
        $this->students = Student::whereHas('profile', function($query) {
            $query->whereHas('user', function ($query) {
                $query->where('name', 'like','%'.$this->search.'%');
            });
        })->take(300)->get();

        $this->showResults = true;
    } else {
        $this->students = [];
        $this->showResults = false;
    }
}
public function updatedSearch()
{
    $this->studentName = $this->search;
}
public function selectedStudent($id)
{
    $student = Student::find($id);
    if ($student && $student->profile && $student->profile->user) {
        $this->search = $student->profile->user->name;
    }
    $this->studentSelected = $id;
    $this->students = [];
    $this->showResults = false;
}
public function render()
{
    return view('livewire.student-relation');
}

Blade:

0 likes
1 reply
Snapey's avatar

any time you have a loop, you MUST use wire:key so that livewire knows which rows have been removed

Please or to participate in this conversation.