first commit
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.3) (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled

This commit is contained in:
brusnitsyn
2026-04-06 00:06:00 +09:00
commit fb2e6c58e3
409 changed files with 42953 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
<?php
namespace App\Rules;
use App\Models\Team;
use App\Models\TeamInvitation;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Translation\PotentiallyTranslatedString;
class UniqueTeamInvitation implements ValidationRule
{
public function __construct(protected Team $team)
{
//
}
/**
* Run the validation rule.
*
* @param Closure(string, ?string=): PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$email = strtolower($value);
$isMember = $this->team->members()
->whereRaw('LOWER(email) = ?', [$email])
->exists();
if ($isMember) {
$fail(__('This user is already a member of the team.'));
return;
}
$hasPendingInvitation = TeamInvitation::where('team_id', $this->team->id)
->whereRaw('LOWER(email) = ?', [$email])
->whereNull('accepted_at')
->where(function ($query) {
$query->whereNull('expires_at')
->orWhere('expires_at', '>', now());
})
->exists();
if ($hasPendingInvitation) {
$fail(__('An invitation has already been sent to this email address.'));
}
}
}