I am creating a migration in Laravel, and I have a field defined like this:
$table->char('código', 3);
The code data should be made up of three digits, from 000
to 999
, but I can not use a numeric field, because the leading zeros should also appear. So, I have to use a field char
, but add some kind of restriction, so that I only accept values formed by, exactly, three digits.
The question is whether this can be specified in any way in the migration, or in the model, or by programming in the controllers that affect this field. I am using the MySQL driver. As the migration refers only to the structure of the table, I do not see very clearly that this is the right place for this restriction.
Has anyone had to do this before?
Thank you.