Support the ongoing development of Laravel.io →
Database Eloquent

I have a multi-tenant DB that I need to manage incrementing invoice numbers per tenant. It's important that i never have any gaps or duplicates for the invoice numbers. I'm using mysql for the database. Is there a best practice to do this using laravel?

What a transaction would look like:

  1. User inputs using UI
  2. Clicks Save
  3. Validate data, if fails, go back to #1
  4. Get next invoice number to assign to this transaction
  5. Save invoice
  6. Commit used invoice number

If anything fails in #4, #5 and #6, I need to roll everything back. Also, if another user tries to save an invoice at the same time, I need to make sure they don't duplicate invoice numbers. Need to make sure no gaps or duplicates for any reason for the invoice number.

Recommendation on how to best do this?

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

korazy8s korazy8s Joined 26 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.