diff --git a/.gitignore b/.gitignore
index 9bb2800..5e7ced7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,4 @@ phpunit.phar
/.settings
.env.*.php
.env.php
+bin
diff --git a/README.md b/README.md
index ef7eaba..c86aedb 100644
--- a/README.md
+++ b/README.md
@@ -28,7 +28,7 @@ Teamwork is the fastest and easiest method to add a User / Team association with
- [Inviting others](#inviting-others)
- [Accepting invites](#accepting-invites)
- [Denying invites](#denying-invites)
- - [Attach/Detach Events](#events)
+ - [Attach/Detach/Invite Events](#events)
- [Limit Models to current Team](#scope)
- [License](#license)
@@ -363,14 +363,16 @@ if( $invite ) // valid token found
The `denyInvite` method is only responsible for deleting the invitation from the database.
-### Attaching/Detaching Events
+### Attaching/Detaching/Invite Events
-If you need to run additional processes after attaching or detaching a team from a user, you can Listen for these events:
+If you need to run additional processes after attaching/detaching a team from a user or inviting a user, you can Listen for these events:
```php
\Mpociot\Teamwork\Events\UserJoinedTeam
\Mpociot\Teamwork\Events\UserLeftTeam
+
+\Mpociot\Teamwork\Events\UserInvitedToTeam
```
In your `EventServiceProvider` add your listener(s):
@@ -389,10 +391,13 @@ protected $listen = [
\Mpociot\Teamwork\Events\UserLeftTeam::class => [
App\Listeners\YourLeftTeamListener::class,
],
+ \Mpociot\Teamwork\Events\UserInvitedToTeam::class => [
+ App\Listeners\YourUserInvitedToTeamListener::class,
+ ],
];
```
-Each event exposes the User and Team's ID. In your listener, you can access them like so:
+The UserJoinedTeam and UserLeftTeam event exposes the User and Team's ID. In your listener, you can access them like so:
```php
getInvite()->user;
+ // $teamId = $event->getTeamId();
+
+ // Do something with the user and team ID.
+ }
+}
+```
+
### Limit Models to current Team
diff --git a/src/Mpociot/Teamwork/Events/UserInvitedToTeam.php b/src/Mpociot/Teamwork/Events/UserInvitedToTeam.php
new file mode 100644
index 0000000..629847a
--- /dev/null
+++ b/src/Mpociot/Teamwork/Events/UserInvitedToTeam.php
@@ -0,0 +1,37 @@
+invite = $invite;
+ }
+
+ /**
+ * @return Model
+ */
+ public function getInvite()
+ {
+ return $this->invite;
+ }
+
+ /**
+ * @return int
+ */
+ public function getTeamId()
+ {
+ return $this->invite->team_id;
+ }
+}
\ No newline at end of file
diff --git a/src/Mpociot/Teamwork/Teamwork.php b/src/Mpociot/Teamwork/Teamwork.php
index fc0b3bd..c6cf667 100644
--- a/src/Mpociot/Teamwork/Teamwork.php
+++ b/src/Mpociot/Teamwork/Teamwork.php
@@ -1,6 +1,7 @@
$team->getKey()
]);
}
-
+
+ public function testInviteToTeamFiresEvent()
+ {
+ $team = TeamworkTeam::create(['name' => 'Test-Team 1']);
+ $invite = $this->createInvite($team);
+ $this->expectsEvents(\Mpociot\Teamwork\Events\UserInvitedToTeam::class);
+ }
}