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

RonB1985's avatar

Relations

I have three tables which are all related to a user (they all belong to a user), as well as to each other. Some examples to show the relations:

http://www.laravelsd.com/share/R8DYhg

http://laravel.io/bin/Nkeve

I have an appointments page where a user can add an appointment, but it needs to have a label attached to it, as well as a status. A label can be something like "Personal", "Business", and a status something like "Open", "Closed", etc. The user can create the labels and the statuses themselves.

Right now I have a label_id and a status_id in the appointments table, and I query results based on the id's which are stored in there. It all works as it should be, but now I want to change my "Create Appointment" form, and make sure that users can fill out a field to create a new label or status on the fly.

My question is, can I create something better instead of the label_id and status_id in the appointments table? I am asking because with the above changes, there will be a lot of if's. For example, I need to check if the user selected an existing label/status from the dropdown, or if they entered a new label/status using the field, andperform the right save query based on those results, and so on.

I also have a contact_id or a relation_id, but I am using polymorphism for those, too bad I cannot use polymorphism for this in some way. But maybe there is a better way than what I have so far.

0 likes
0 replies

Please or to participate in this conversation.