0

I have data in an array that contains hotels' names with their id. I want to place them in my select where I will display only the city an grab the id to do ajax and display rooms name. The problem is it is displaying both the name of the hotel and the id array in my dropdown. this is my controller.

 foreach ($hotel as $nam ){
   $hotel_nam[]=$nam->id;
   $hotel_nam[]=$nam->hotel_name;             
  }
  return  $hotel_nam;

this is my drop down

  {!! Form::select('hotel_name',$hotel_nam,'S', array('style'=>' Border:none; ', 'id' => 'hotel_id', 'onchange'=>"showRooms(this.value)"));!!}

1 Answer 1

1
$hotelLists = [''=>'--Select Hotel--'];
foreach ($hotel as $nam) {
    $hotelLists[$nam->id] = $nam->hotel_name;
}

{!! Form::select('hotel_name',$hotelLists,'', array('style'=>' Border:none; ', 'id' => 'hotel_id', 'onchange'=>"showRooms(this.value)"));!!}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.