Skip to content

Commit 593e763

Browse files
committedJan 19, 2021
fix unique check
1 parent 56271e6 commit 593e763

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed
 

‎stubs/app/Actions/Jetstream/InviteTeamMember.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Support\Facades\Gate;
66
use Illuminate\Support\Facades\Mail;
77
use Illuminate\Support\Facades\Validator;
8+
use Illuminate\Validation\Rule;
89
use Laravel\Jetstream\Contracts\InvitesTeamMembers;
910
use Laravel\Jetstream\Events\InvitingTeamMember;
1011
use Laravel\Jetstream\Jetstream;
@@ -51,7 +52,7 @@ protected function validate($team, string $email, ?string $role)
5152
Validator::make([
5253
'email' => $email,
5354
'role' => $role,
54-
], $this->rules(), [
55+
], $this->rules($team), [
5556
'email.unique' => __('This user has already been invited to the team.'),
5657
])->after(
5758
$this->ensureUserIsNotAlreadyOnTeam($team, $email)
@@ -61,12 +62,15 @@ protected function validate($team, string $email, ?string $role)
6162
/**
6263
* Get the validation rules for inviting a team member.
6364
*
65+
* @param mixed $team
6466
* @return array
6567
*/
66-
protected function rules()
68+
protected function rules($team)
6769
{
6870
return array_filter([
69-
'email' => ['required', 'email', 'unique:team_invitations'],
71+
'email' => ['required', 'email', Rule::unique('team_invitations')->where(function ($query) use ($team) {
72+
$query->where('team_id', $team->id);
73+
})],
7074
'role' => Jetstream::hasRoles()
7175
? ['required', 'string', new Role]
7276
: null,

0 commit comments

Comments
 (0)