I've got a column with house numbers saved as a varchar in my database. Possible options are:
- Number
- Number + Character
- Number + Multiple characters
- Number - Number
I would like to order this column numerical. For example
120, 18, 198CC, 9A, 42-44, 198C, 9C, 9AC, 7B, 318, 7
Should become
7, 7B, 9A, 9AC, 9C, 18, 42-44, 120, 198C, 198CC, 318
When using a regular ...->orderBy('number')
the result is based on the length of the string instead of the numeric value. When using ->orderByRaw('CAST(amount AS DECIMAL)')
I'm getting an error because the characters can't be converted to a decimal.
Someone with a solution for this case?