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

kreierson's avatar

V-model with transnational data

I have a system where a customer can make a reservation for a trip. On that reservation they can choose a package. Below is an example of my tables for these two objects.

Reservations Table

id | customer_id | price | no_of_people | package_id | package_name | package_price

1 | 550 | 15000 | 2 | 1 | Lodging | 9000

2 | 499 | 15000 | 2 | 2 | Ultimate | 13000

Package Table

id | name | price

1 | Lodging | 9000

2 | Ultimate | 13000

Creating a reservation and using v-model on the select box is straight forward

<select class="form-control form-control-sm" v-model="reservation.package">
    <option v-for="package in available_packages" :value="package">
          {{package.name}}
    </option>
</select>
                                        

My issue comes into play when I am building the edit form. I want them to be able to update the package and if i use v-model just like above, I run into an issue if the admin decides to update the price or name of the package. If the name or price is updated, the name and most importantly the price gets updated. When the reservation was made, the customer expects to pay that price, but if the company updates the package, now the relationship is looking at the updated price.

Since the reservation is a transaction, I need to capture that price on the reservation at the time of booking, so how would I use v-model on a select box when I need to show pricing information from the reservation table for the selected package, and not the price from the package table.

I hope that makes sense. Thanks!

0 likes
1 reply
kreierson's avatar
kreierson
OP
Best Answer
Level 13

I guess I can v-model on the id of the package in the reservation and package table. Then do array.filter() to get the selectedPackage from the available packages to show pricing info on the page.

Please or to participate in this conversation.