Does it matter if there is a gap?
Can you not use the Auto incrementing database row ID as the count?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Guys iam working with a project inventory control like system.
i have a purchase order form. the purchase_order_number will be automatically generated.
what i did is,
fetched the last id of the purchase table and added few strings POID and retruned it the the view.
so each and every time there will be new purchase order id.
but i faced many problems in that.
whats happening is i will check if any record is there in table. if not there the order id must be POID1 else if any record available then take the id add 1 with the id then add the string.
this is what i will do
$pur_id=PurchaseOrder:: select('id')->orderBy('created_at','asc')->first();
if($pur_id==null)
{
$pur_id='POID1';
}
else
{
$pur_id->id;
$pur_id =$pur_id->id+1;
$pur_id= 'POID'.$pur_id;
}
dd($pur_id);
but all the time this wont work. because some times the order id becomes same due to Internet reload. like that issues.
if i delete all the records from the table.
the first order number fills right, but after the the order number changes without any serial number because it takes the deleted id of that.
now whats my expectation is, need a unique purchase order id, with POID with series of numbers like POID1, POID2, POID3, POID4 likes this need to go on, else can i add todays date with that id like that.
Kindly suggest, any idea please and help me.
Please or to participate in this conversation.