Just FYI, there are several good past post on this where myself and others have given examples.
But you can get the id of the new record and build off of that.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I want to generate an incremental invoice number with a prefix using the user's branch eg. ABC00001 but I don't know how. I am currently using the date and time as an invoice number. I am on Laravel 9.
private function generateInvoiceNumber() { $branch_code = Auth::user()->branch; $currentDateTime = Carbon::now(); $formattedDateTime = $currentDateTime->format('YmdHis'); $invoiceNumber = $branch_code . $formattedDateTime;
return $invoiceNumber;
}
Please or to participate in this conversation.