A common pattern when modernizing an older Laravel application is to identify groups of related string values and represent them as a string-backed enum.
This adds consistency to your codebase, improves type safety, and makes it easier to understand the possible values for a given field.
But one additional consideration is migrating that legacy data into the new enum format.
It's common for MySQL databases to use a case-insensitive collation for string fields. This means that values like "active", "Active", and "ACTIVE" would all be considered equivalent in the database.
PHP enums are case-sensitive though, so if you're using an enum cast on your Eloquent model, unless you normalize the data during migration, you will get a ValueError when Eloquent tries to cast a value that doesn't exactly match one of the enum cases.
I typically use lower-case backed values for enums, so a SQL query like this would solve the problem:
UPDATE table_name
SET new_enum_field = LOWER(new_enum_field);
Here to help,
Joel
P.S. Would you like help modernizing your Laravel application? Leverage our experience to make your project a success.