Published 4 months ago by MyLibrary
Hey guys, I would like to generate a unique reference code in my system for Orders, Procurement and Transactions. Do you have any suggestions how big should be the reference code and how should I implement it in an efficient way? The system should have xxx procurement per year, xxxx orders per year and about xxxx transactions per year.
Thanks for your help!
@cawex, I can use a validation to check if it unique, otherwise creating a new uniqid(). The prefix suggestion will create different size reference code with time, and I would prefer to keep it at the same length at this moment.
@Talky, that idea might work, but bcrypt generates a long reference code.
I wonder if there is something not too short and not too long that will include the microtime, the model type (for example order) and the model id, and then make a unique string out of that, what do you think guys?
At this moment I'm using:
strtoupper(uniqid('OR')) // OR stands for Orders prefix.
Thanks for your help guys!
I'm still unsure if you need it to be incremental?
Are you wanting it to be 'random' so that it cannot be guessed, or sequential like a an invoice number INV00001, INV00002 etc
If random then you could use a separate table, pre-populated with random reference numbers (all unique). Using transactions, take the next number and store what it was used for (entity and id) ?
Does it need to be a number? Could you use the hashids package?