Level 51
Use wire:model.live to run that hook.
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I am trying to create a 2 level dropdown, but when i choose one option on the first select, the updated function doesn´t trigger. I already debugged, checked logs and i dont see any errors.
Someone can help me please?
<?php
namespace App\Livewire;
use Livewire\Component;
use App\Models\SurveyAccessKey;
use App\Models\Project;
use App\Models\Survey;
class CreateAccessKey extends Component
{
public $projects;
public $surveys;
public $name;
public $project;
public $survey;
public function mount()
{
$this->projects = Project::all();
$this->surveys = collect();
}
public function updated($property, $value)
{
if ($property === 'project') {
$this->surveys = Survey::where('project_id', $value)->get();
}
}
public function storeAccessKey()
{
$this->validate([
'name' => 'required',
'survey' => 'required',
]);
SurveyAccessKey::create([
'name' => $this->name,
'survey_id' => $this->survey,
]);
$this->name = '';
$this->project = '';
$this->surveys = collect();
}
public function render()
{
return <<<'HTML'
<div>
<form wire:submit.prevent="storeAccessKey" class="border-b-2 pb-10">
<div class="mt-4">
<label class="block font-medium text-sm text-gray-700" for="project">
Project*
</label>
<select wire:model="project" name="project"
class="mt-2 text-sm sm:text-base pl-2 pr-4 rounded-lg border border-gray-400 w-full py-2 focus:outline-none focus:border-blue-400" required>
<option value="">-- choose project --</option>
@foreach ($projects as $project)
<option value="{{ $project->id }}">{{ $project->name }} - {{ $project->id }}</option>
@endforeach
</select>
</div>
<div class="mt-4">
<label class="block font-medium text-sm text-gray-700" for="survey">
Survey*
</label>
<select wire:model="survey" name="survey"
class="mt-2 text-sm sm:text-base pl-2 pr-4 rounded-lg border border-gray-400 w-full py-2 focus:outline-none focus:border-blue-400" required>
@if ($surveys->count() == 0)
<option value="">-- choose project first --</option>
@endif
@foreach ($surveys as $survey)
<option value="{{ $survey->id }}">{{ $survey->name }}</option>
@endforeach
</select>
</div>
<div class="flex items-center mt-4">
<button type="submit"
class="inline-flex items-center px-4 py-2 bg-gray-800 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700 active:bg-gray-900 focus:outline-none focus:border-gray-900 focus:shadow-outline-gray disabled:opasurvey-25 transition ease-in-out duration-150">
Add Survey Access Key
</button>
</div>
</form>
</div>
HTML;
}
}
Use wire:model.live to run that hook.
Please or to participate in this conversation.