I'm doing some tests using livewire components and what I need is to get the value of a select and show it in a , I already have the part of managing the load of the Select solved and working, and what I'm missing is being able to catch the value of the selected item. I show you the code of the component.
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\Cliente;
class Clientes extends Component
{
public $buscar;
public function render()
{
$datos = Cliente::where('raz_social', 'like' , '%' . $this->buscar . '%')
->orderBy('raz_social')->get();
return view('livewire.clientes', ['dtosclie' => $datos]);
}
}
and here the view:
<div>
<div class="flex flex-col">
<input class="mb-1 bg-transparent border-0 border-b-2" type="text" placeholder="Nombre del cliente..." wire:model="buscar">
<span>Aqui quiero poner el valor del cod_cli seleccionado</span>
<select class="form-select rounded-lg">
<option value="">Seleccionar...</option>
@foreach($dtosclie as $it)
<option value="{{ $it->cod_cli}}">{{ $it->raz_social}}</option>
@endforeach
</select>
</div>
</div>
Thanks and regards
you must create a wire:model in the view for the select.
<select class="form-select rounded-lg" wire:model='selectedInput'>
and in the controller you must declare that model with a null or empty value, so that it does not display anything until it has a value, it should be something like this.
Success