user = $user; $this->company = $company; } public function handle(): UserInvitation { \DB::transaction(function () { if ($this->user->hasPendingInvitation($this->company->id)) { $pending_invitation = $this->user->getPendingInvitation($this->company->id); $this->dispatch(new DeleteInvitation($pending_invitation)); } $this->invitation = UserInvitation::create([ 'user_id' => $this->user->id, 'company_id' => $this->company->id, 'token' => (string) Str::uuid(), ]); }); event(new InvitationCreated($this->invitation)); return $this->invitation; } }