You would make your life a lot easier by having the user select the hotel first then click a button to add a room to it.
You can then load the amenities applicable to that hotel and send them to the view
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, I am working on a reservation system for a hotel using laravel. My models include hotel, room and amenities. A room belongs to a hotel whereas a room can have many amenities. Now, while editing the room model, I have a select box of all the hotels as well as a multiple select of all the amenities. However, i need the hotel and amenities fields to be populated with the relevant data for the hotel while editing. How can i achieve this?
Thank you.
Here's the code
edit.blade.php
@extends('backend/layouts/template')
@section('title')
Edit Room
@endsection
@push('dashboard-styles')
<link href="{{ asset('css/plugins/chosen/bootstrap-chosen.css') }}" rel="stylesheet">
<link href="{{ asset('css/plugins/select2/select2.min.css') }}" rel="stylesheet">
<link href="{{ asset('css/plugins/jasny/jasny-bootstrap.min.css') }}" rel="stylesheet">
@endpush
@section('page-header')
<div class="row wrapper border-bottom white-bg page-heading">
<div class="col-lg-10">
<h2>Edit Room</h2>
<ol class="breadcrumb">
<li>
<a href="">Home</a>
</li>
<li>
<a>Hotel Management</a>
</li>
<li>
<a>Rooms</a>
</li>
<li class="active">
<strong>Edit {{ucfirst($room->name) }} Room</strong>
</li>
</ol>
</div>
<div class="col-lg-2">
</div>
</div>
@endsection
@section('content')
<div class="row">
<div class="col-lg-12">
<div class="ibox-float-e-margins">
<div class="ibox-title">
<h5>{{ $room->name }}'s details</h5>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
</a>
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-wrench"></i>
</a>
<ul class="dropdown-menu dropdown-user">
<li><a href="#">Config option 1</a>
</li>
<li><a href="#">Config option 2</a>
</li>
</ul>
<a class="close-link">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<div class="ibox-content">
<div class="row">
<div class="col-sm-12 b-r">
<form action="{{ route('rooms.update', $room->id) }}" method="POST" enctype="multipart/form-data" >
{{ csrf_field() }}
{{ method_field('PATCH') }}
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label>Name</label>
<input type="text" value="{{ $room->name }}" name="name" class="form-control" required>
<!-- If first name has error -->
@if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
@endif
</div>
<div class="form-group{{ $errors->has('hotel_id') ? ' has-error' : '' }}">
<label>Hotel</label>
<select class="chosen-select form-control" data-placeholder="Select Hotel" id="hotel_id" name="hotel_id" tabindex="2" required>
<option></option>
@foreach($hotels as $hotel)
<option value="{{ $hotel->id }}">{{ $hotel->name }}</option>
@endforeach
</select>
<!-- If first name has error -->
@if ($errors->has('hotel_id'))
<span class="help-block">
<strong>{{ $errors->first('hotel_id') }}</strong>
</span>
@endif
</div>
<div class="form-group{{ $errors->has('amenities') ? ' has-error' : '' }}">
<label>Amenities</label>
<select class="chosen-select form-control" data-placeholder="Select Amenity(ies)" id="amenities" name="amenities[]" tabindex="2" required multiple="multiple">
<option></option>
@foreach($amenities as $amenity)
<option value="{{ $amenity->id }}">{{ $amenity->name }}</option>
@endforeach
</select>
<!-- If first name has error -->
@if ($errors->has('amenities'))
<span class="help-block">
<strong>{{ $errors->first('amenities') }}</strong>
</span>
@endif
</div>
<div class="form-group{{ $errors->has('price') ? ' has-error' : '' }}">
<label>Price</label>
<input type="text" placeholder="Price per night" name="price" class="form-control" required>
<!-- If first name has error -->
@if ($errors->has('location'))
<span class="help-block">
<strong>{{ $errors->first('price') }}</strong>
</span>
@endif
</div>
<div class="form-group{{ $errors->has('no_of_persons') ? ' has-error' : '' }}">
<label>Number of people room can accomodate</label>
<input type="number" placeholder="eg 5" name="no_of_persons" class="form-control" required>
<!-- If first name has error -->
@if ($errors->has('no_of_persons'))
<span class="help-block">
<strong>{{ $errors->first('no_of_persons') }}</strong>
</span>
@endif
</div>
<div class="fileinput fileinput-new input-group form-group{{ $errors->has('image') ? ' has-error' : '' }}" data-provides="fileinput">
<div class="form-control" data-trigger="fileinput">
<i class="fa fa-file fileinput-exists"></i>
<span class="fileinput-filename"></span>
</div>
<span class="input-group-addon btn btn-default btn-file">
<span class="fileinput-new">Select file</span>
<span class="fileinput-exists">Change</span>
<input type="file" name="image" required/>
</span>
<a href="#" class="input-group-addon btn btn-default fileinput-exists" data-dismiss="fileinput">Remove</a>
<!-- If first name has error -->
@if ($errors->has('image'))
<span class="help-block">
<strong>{{ $errors->first('image') }}</strong>
</span>
@endif
</div>
<div class="form-group{{ $errors->has('room_information') ? ' has-error' : '' }}">
<label>Room information</label>
<textarea name="room_information" placeholder="Say more about the room" rows="10" class="form-control" required></textarea>
<!-- If first name has error -->
@if ($errors->has('description'))
<span class="help-block">
<strong>{{ $errors->first('description') }}</strong>
</span>
@endif
</div>
<div>
<!-- <button type="submit" class="btn btn-sm btn-block btn-primary pull-right">Update</button> -->
<button type="submit" class="btn btn-primary">Update</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
@endsection
@push('dashboard-scripts')
<!-- Chosen -->
<script src="{{ asset('js/plugins/chosen/chosen.jquery.js') }}"></script>
<!-- Select2 -->
<script src="{{ asset('js/plugins/select2/select2.full.min.js') }}"></script>
<!-- Jasny -->
<script src="{{ asset('js/plugins/jasny/jasny-bootstrap.min.js') }}"></script>
<script>
$(document).ready(function(){
$('.chosen-select').chosen({width: "100%"});
});
</script>
@endpush
RoomController.php
public function edit($id)
{
$room = Room::find($id);
$amenities = Amenity::all();
$hotels = Hotel::all();
return view('backend/rooms/edit', compact('room', 'amenities', 'hotels'));
}
Please or to participate in this conversation.