I'm currently looking at the code I've produced and I'm trying to improve its readability and quality. Here's an example of how I'd approach a simple problem, which I've always felt was a poor solution.
Users table with the below "statuses", or elevation levels in this example
- Employee
- Supervisor
- Admin
(these could be anything, for example, a project could have an "incomplete", "on hold" and "complete" status)
In the past, I've always stored this as an INT value then when printing out the accounts and their statuses, I will write a function to convert this back to text, to be printed on a page e.g.
if userLevel === 3 { return "Admin"; };
This has always felt like a bad solution, and it's not very flexible. The addition of any new types of account would require the function to be updated. This format also makes it very difficult to read page restrictions.
If I were to add the line:
if userLevel !== 2 OR 3 { // Redirect to error page };
You can see how this could become confusing down the line.
Recently I've started storing these "statuses" as a string purely so it's more readable. But now I've been getting more into Laravel, I wonder if I should have additional database tables devoted solely to this.
So my question - what is the appropriate data type for this kind of data, and what would be the ideal way to interact with it?