0

Does anyone, that works/has worked with laravel know how to give id a minimum length?

For example, instead of 1 I would want 000001, 10 would be 000010, and so on.

I know uuid does something similar, but it's not exactly what I want. Also, I had a bad experience with uuid, where I wanted to delete the field but it would still show up every time I migrated 🙃 but it wasn't it the migration file 🙃 so now I try to avoid using it 🙃

Comments
  • 0
    This is gonna happen at rendering time, not storing time. Just keep storing as integer but format the string differently
  • 0
    Well, that really depends.

    A) You store them as Auto increment - then on display time - you modify to add pads (`0` to the start). This can be done in model with getIdAttribute.
    B) You store the integer with mutation manually and hope for the best to avoid conflicts with big data. Then all you need to do is format it before sending and vuolia - you have what you need.

    IMHO: I'd go for the A.
  • 0
    @beegC0de @potata that's exactly what I wanted to avoid doing (option A). What I'm doing will be used in a lot of different places for a lot of different things and I didn't want to do that every-single-time a need to select something from that table.

    I just hope laravel comes up with a better solution for this.
  • 0
    It is almost certainly a cleaner solution than coming up with a different way to represent integers in storage
Add Comment