I have these tables: contacts
, tags
, contact_tags
.
(contact_tags
has columns contact_id
and tag_id
.)
Administrators can manually create new tags via an internal website.
Administrators can also associate a tag to a contact (i.e. create a new contact_tag
).
Non-admin visitor behaviors can also cause the creation of a contact_tag
.
Certain tags are really important, and when one of these important tags is being associated with a contact (i.e. its tag_id
is in the contact_tag
being created either manually by an admin or via a visitor behavior), certain functions need to run.
To achieve this, there are various tag IDs hard-coded in my code. This smells bad, but I haven't figured out a better approach, so I'm wondering what the best practice is.
For example, my code might say:
const TAG_DEPOSIT_PAID = 67;
//(and many other constants of IDs specified here too)
and then somewhere in ContactTagAddedEventListener
:
if($tag->id == Tag::TAG_DEPOSIT_PAID){
//do stuff
}
How should can I improve my architecture?
(By the way, for testing purposes, my database seeder seeds a testing database with all the "important" tags referenced by these different functions.)
P.S. My understanding is that enums are almost always bad and that tables like my tags
table are generally better, but I'm clearly missing some other principles because my approach doesn't feel clean.