Hello in my laravel application I have a function that generates a unique receipt code whenever a customer completes a transaction.
This is the format of the code: 1. 4 Digit Identifier of Store eg. ABCD 2. Type or Category of item purchased. eg. E for electronics, T for toys 3. Special secret two digit code eg. can be between 01 and 10. 4. Date in really short format. eg. 31J16 for 31st January, 2016 5. Four digit code for customers to use for support issues or returning an item. eg. 3267. This is randomly generated.
So a sample would look like this: ABCDT0131J163267 Total length is 16 characters.
Now what I want to do is each time a code is generated make sure it does not already exist in my database if yes then it should generate a new one and so on till it comes up with a unique code.
Now my issue is getting an efficient solution t generate unique codes that won't end up looping soo many times like I intend on doing.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire