How do I generate a random reference?
I've got a resource with a
reference
field that I want to automatically generate a random identifier for.
The user opens the record creation page, and the default value is "INV-0001" or "INV-4829" (haven't decided if I want it to be random or incremented yet).
How do I do that?6 Replies
Invoices should be incremental really for accounting reasons. You can start the first one higher if need be.
Otherwise as Leandro mentioned.
Or via the model creating function you set it on create in the model which would cover your API use case if you ever wanted to automate creating invoices from anywhere.
That's not what I want to happen tho. I want the form to by default fill with something like INV-0001 and then the user can change it in the form.
Basically, I want it to suggest INV-0001 and the user can change it if need be.
So then you want to use ->default with a closure
Solution
Perfect, thank you!