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

ajck's avatar
Level 1

How to model guests in a (hotel) booking? (not one-to-many relationship?)

I have an accommodation booking site and in my database I have a guests table and a bookings table, and I need to relate a booking to the specific guests for that booking. There could potentially be any number of guests.

The obvious solution on the face of it would be a one (booking) to many (guests) relationship as per here: https://laravel.com/docs/5.4/eloquent-relationships#one-to-many but this then sets a foreign key on a guest tying it to that specific booking. But of course guests will make many bookings over time so each guest record can not be permanently hard wired to a specific booking.

My idea therefore was simply to store guest IDs in a string on the booking separated by pipes '|' and do a 'manual' lookup when I want to find guests associated with a booking. But is there a better way of modelling this (in either SQL or Laravel or Eloquent)? I'm using MariaDB/MySQL as the database, if that makes any difference.

Thanks

0 likes
2 replies
ajck's avatar
Level 1

Ah yes that would work, great thanks

Please or to participate in this conversation.