-1
I would like to make a dynamic select so that when I choose the state, load the cities of that state into the other select.
City and state are in different tables, but have foreign key, so when I register a city, it is automatically identified which state it belongs to.
It has already been made Belong to relation of city to state and has Many of state to city.
Select on Slide is like this:
<div class="row gy-3">
<div class="col-6">
<label class="form-label">Estado: </label>
<select class="form-select form-select-md" name="unifed" class="form-control" id="uf_id">
<option selected>Selecione</option>
@foreach($ufs as $uf)
<option value="{{ $uf['id'] }}"> {{ $uf['sigla'] }} </option>
@endforeach
</select>
</div>
<div class="col-6">
<label class="form-label">Cidade: </label>
<select class="form-select form-select-md" name="cidade" class="form-control" id="cidade_id">
<option selected>Selecione</option>
@foreach($cidades as $cidade)
<option value="{{ $cidade['id'] }}"> {{ $cidade['nome'] }} </option>
@endforeach
</select>
</div>
What do I need to change? For in the city select is showing all cities.
I have tried several solutions but none worked.
If anyone can help me, I appreciate it now. This is really very important.
Thank you! Friend, I understood the code and its logic being that now the list of cities is empty. Regardless of whether I choose a state, the list of cities isn’t pulling the cities from the bank. The public Function findcity I put in the City Controller. This correct?
– Victoria
Vitória, the controller you put is indifferent, because the route will redirect to the controller you indicated, and this will perform the function, so I do not believe this is the problem. The error could be in many places, I would have to have more information to tell you the reason for the error. First, it is running the Function changeCity? (gives a console.log in the function to check). If so, is it falling into the controller’s findCity function? (you can use php dd() to find out). And tell me the error that’s happening
– Daniel Kartabil Bernardi
lacked an "n" in select, I wrote "econtrar-city" instead of "find-city", maybe the mistake is this.
– Daniel Kartabil Bernardi