Laravel Queue Getting Duplicate Values

I am using laravel queue to get laters record of users

If two users use the same functaion at same time , the values get replicated

this is my code on controller

.......
SendInvitation::dispatch($email,$name,$nhs_number,$appInfo,$userInfo)->onQueue('high'); ........  SendInvitation on quaue code public function handle() { try {$user = User::orderBy('created_at','DESC')->first();

if($user != null){$enu_id = $user->invitation_id; }else{$enu_id = "EAA-0001-1";
}
$strArray = explode('-',$enu_id );
$x =$strArray[0];
if($strArray[0] ==$x){
if($strArray[1] < 9999){$get_id = $strArray[1];$e_id = $x.'-'.$get_id.'-';
}else{
$x++;$e_id = $x.'-0001-'; } }else{ if($strArray[1] < 9999){
$x++;$get_id = $strArray[1];$e_id = $x.'-'.$get_id.'-';

}else{
$x++;$e_id = $x.'-0001-'; } } } } ..........  I am getting the latest users$enu_id and

with a algorithum i am incrementing it

Its working fine….

my problem is if two users register at the same time the both gets the same id

it is wrong , that’s why i have used Queaue

Is there any way not to stop overlapping until a queue gets over?

Thank you ….

Source: Laravel