@@ -383,19 +383,21 @@ public function inviteUser(InviteUserRequest $request)
383383 $ user ->assignSingleRole ($ request ->input ('user.role_uuid ' ));
384384 }
385385
386- $ invitation = Invite::create ([
387- 'company_uuid ' => $ company ->uuid ,
388- 'created_by_uuid ' => session ('user ' ),
389- 'subject_uuid ' => $ company ->uuid ,
390- 'subject_type ' => Utils::getMutationType ($ company ),
391- 'protocol ' => 'email ' ,
392- 'recipients ' => [$ user ->email ],
393- 'reason ' => 'join_company ' ,
394- 'meta ' => array_filter (['role_uuid ' => $ request ->input ('user.role_uuid ' ) ?? $ request ->input ('user.role ' )]),
395- 'expires_at ' => now ()->addHours (48 ),
396- ]);
386+ if (!Invite::isAlreadySentToJoinCompany ($ user , $ company )) {
387+ $ invitation = Invite::create ([
388+ 'company_uuid ' => $ company ->uuid ,
389+ 'created_by_uuid ' => session ('user ' ),
390+ 'subject_uuid ' => $ company ->uuid ,
391+ 'subject_type ' => Utils::getMutationType ($ company ),
392+ 'protocol ' => 'email ' ,
393+ 'recipients ' => [$ user ->email ],
394+ 'reason ' => 'join_company ' ,
395+ 'meta ' => array_filter (['role_uuid ' => $ request ->input ('user.role_uuid ' ) ?? $ request ->input ('user.role ' )]),
396+ 'expires_at ' => now ()->addHours (48 ),
397+ ]);
397398
398- $ user ->notify (new UserInvited ($ invitation ));
399+ $ user ->notify (new UserInvited ($ invitation ));
400+ }
399401
400402 return response ()->json (['user ' => new $ this ->resource ($ user )]);
401403 }
0 commit comments