I am working on a hotel reservation system, where user|admin can select multiple rooms for Reservation. I am facing a problem in the edit functionality. I am looking for help and suggestions on how to make this right.
My schema.
Rooms:
room_number
price
reserved(Boolean)
maintenance(Boolean)
Reservations:
customer_id
checkin
checkout
Reservation_Room
room_id
reservation_id
TotalPrice
Query scope on rooms
public function scopeIsNotReserved($query)
{
return $query->where('reserved', false);
}
Relationship Reservation Model:
public function rooms()
{
return $this->belongsToMany(Room::class);
}
The actual problem is.
I cannot use IsNotReserved query scope
while editing a reservation, because it won't pass the value to the selected options. I would like to pass all the rooms that are not reserved except this reservation.id(See $roomId
) My controller edit function looks like this.
$reservation = Reservation::findOrFail($id);
$customers = Customer::pluck('name', 'id')->toArray();
// Currently not doing anything with this query.
$roomId = $reservation->rooms()->pluck('rooms.id')->toArray();
Getting All Rooms
$rooms = Room::IsNotOnMaintenance()->get();
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire