Alias table column values in laravel?

Viewed 129

I'm converting an older system to laravel/eloquent and I'm still somewhat new to all the 'toys' built in to the ORM. Often I code out something and find out something like it already exists in the back-end code.

What I have is a table of records where the 'name' field has either changed spelling over time, it is occasionally abbreviated, gets changed in API input or is frequently mis-spelled in manual input. (I'm not entirely sure which of the four is the reasoning) So it utilizes additional records and columns to deal with the alternate names and abbreviations.

I would usually code this sort of thing with a second 'aliases' table for the alternate/abbreviated variations pointing back to the primary (proper) named record in the main table. If it's not found by the exact name, check the 'aliases' table and return the record it points to.

Before I code a getByName() set of methods and overrides to some of the standard model methods, I'm wondering if there is anything built in that might already handle this. (I'm aware I could set up a second table with a many-to-one relationship just for names - I'm just wondering if there's anything else hiding out there)

0 Answers
Related