Skip to content

Commit

Permalink
fix unique check
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 19, 2021
1 parent 56271e6 commit 593e763
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions stubs/app/Actions/Jetstream/InviteTeamMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Laravel\Jetstream\Contracts\InvitesTeamMembers;
use Laravel\Jetstream\Events\InvitingTeamMember;
use Laravel\Jetstream\Jetstream;
Expand Down Expand Up @@ -51,7 +52,7 @@ protected function validate($team, string $email, ?string $role)
Validator::make([
'email' => $email,
'role' => $role,
], $this->rules(), [
], $this->rules($team), [
'email.unique' => __('This user has already been invited to the team.'),
])->after(
$this->ensureUserIsNotAlreadyOnTeam($team, $email)
Expand All @@ -61,12 +62,15 @@ protected function validate($team, string $email, ?string $role)
/**
* Get the validation rules for inviting a team member.
*
* @param mixed $team
* @return array
*/
protected function rules()
protected function rules($team)
{
return array_filter([
'email' => ['required', 'email', 'unique:team_invitations'],
'email' => ['required', 'email', Rule::unique('team_invitations')->where(function ($query) use ($team) {
$query->where('team_id', $team->id);
})],
'role' => Jetstream::hasRoles()
? ['required', 'string', new Role]
: null,
Expand Down

0 comments on commit 593e763

Please sign in to comment.