@infoflopaydeveloper
You could have one extra field in table, user_id, and get the max id inserted by that user in that table, really one extra field wouldn't be a big deal. This way you know the id is the correct id to build invoice off of.
Basically add record, then turn around and edit it to add the invoice number.
You are looking for the record with a maxid of the user_id
$forinvoice = DB::table('yourtable')->max('id')
->where('user_id', $Auth::id);
Something like that.
Remember add first, then edit to build invoice.
I just typed out quickly, adjust as needed, you are after:
The max id of a record where a user_id is the id of the user who is making an invoice.
You will have no collisions, as long as the edit is the very next thing done.
And as stated pad with zero's as needed.