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

BarthFox's avatar

Dynamic coutry ,state,cities with laravel for search a real state location

Hi! I am new in laravel . I have three tables in relations by eloquent. In my form select i have many states and cities than Countries. so i wish that ,,when i select a country ...i get only states in this country and when i select a state ...i get only cities inside also.

I don't kow how to do it in laravel . Need your help.

Thanks&Regards

0 likes
2 replies
AviationCode's avatar

If you want this to be dynamic without page refresh you'll need some client side library to perform an AJAX request to your server. On your server you can create a couple of API's to filter the data.

If you use just blade no you'll have to do a page refresh / submit and filter the data at that point.

If you could post the code you already have or go a more in detail what you are trying to achieve technical level it would allow us to guide you through the process.

BarthFox's avatar

He is my controller : public function annonces() { $biens = Bien::orderBy('id','desc')->paginate(8); $options = Option::All(); $pays = Pay::All(); $villes = Ville::All(); $quartiers = Quartier::All(); $typebiens = Typebien::All(); return view('portail.acceuil',['biens'=>$biens,'options'=>$options,'pays'=>$pays,'villes'=>$villes,'quartiers'=>$quartiers,'typebiens'=>$typebiens]); }

ANd here my view: <div class="col-lg-2 col-md-12 col-xs-6"> <div class="at-col-default-mar"> <select name="country" id="country"> @foreach($pays as $pay) <option value="0" selected>Pays</option> <option value="{{$pay->id}}">{{$pay->libelle}}</option> @endforeach </select> </div> </div> <div class="col-lg-2 col-md-12 col-xs-6"> <div class="at-col-default-mar"> <select name="state" id="state"> @foreach($villes as $ville) <option value="0" selected>Ville</option> <option value="{{$ville->id}}">{{$ville->libelle}}</option> @endforeach </select> </div> </div> <div class="col-lg-2 col-md-12 col-xs-6"> <div class="at-col-default-mar"> <select name="city" id="city"> @foreach($quartiers as $quartier) <option value="0" selected>Quartier</option> <option value="{{$quartier->id}}">{{$quartier->libelle}}</option> @endforeach </select> </div> </div>

Please or to participate in this conversation.