when loading the user edit form, I can’t set the user’s city
Using Livewire 2.3
Laravel 8
View Blade:
<div class="w-1/6">
<div class="mb-1 relative pt-4">
<label for="estado" class="text-xs text-gray-700 absolute top-0 py-1 ml-2 px-2 bg-white select-none">{{__('Estado')}}</label>
<select wire:model='selectedUf' id="estado" class=" w-full h-8 my-2 border-b border-gray-300 focus:bg-gray-50 hover:bg-gray-50">
<option value="0" selected>Selecione</option>
@foreach($ufs as $uf)
<option value="{{ $uf->cd_uf }}" @if ($uf->cd_uf == $userUf) selected @endif>{{ $uf->ds_uf_sigla }}</option>
@endforeach
</select>
</div>
</div>
Component :
use App\Models\Cidades;
use App\Models\Uf;
use App\Models\User;
use Livewire\Component;
class EditComponent extends Component
{
public $user;
public $state = [];
public $showEditModal = false;
public $ufs;
public $selectedUf = null;
public $cidades = null;
public $userUf;
protected $listeners = ['editUser' => 'editUser'];
public function updatedSelectedUf($uf)
{
if (!is_null($uf)) {
$this->cidades = Cidades::where('cd_uf', $uf)->get();
}
}
public function editUser(User $user)
{
$this->showEditModal = true;
$this->user = $user;
$this->userUf = $user->uf->id_uf;
$this->state = $user->toArray();
}
public function addUser()
{
$this->showEditModal = false;
}
public function close()
{
$this->showEditModal = false;
$this->user = null;
}
public function mount()
{
$this->ufs = Uf::all();
}
public function render()
{
return view('livewire.painel.usuarios.edit-component');
}
}